T Sql 简明教程

T-SQL - Drop Tables

SQL Server DROP TABLE 语句用于删除表定义以及表的所有数据、索引、触发器、约束和权限规范。

The SQL Server DROP TABLE statement is used to remove a table definition and all data, indexes, triggers, constraints, and permission specifications for that table.

Note − 使用此命令时必须小心,因为一旦表被删除,表中提供的所有信息也将永远丢失。

Note − You have to be careful while using this command because once a table is deleted then all the information available in the table would also be lost forever.

Syntax

以下是 DROP TABLE 语句的基本语法 −

Following is the basic syntax of DROP TABLE statement −

DROP TABLE table_name;

Example

让我们先验证 CUSTOMERS 表,然后从数据库中删除它 −

Let us first verify CUSTOMERS table and then we will delete it from the database −

Exec sp_columns CUSTOMERS;

以上命令显示了以下表。

The above command shows the following table.

TABLE_QUALIFIER   TABLE_OWNER   TABLE_NAME   COLUMN_NAME   DATA_TYPE   TYPE_NAME
   PRECISION   LENGTH SCALE   RADIX   NULLABLE   REMARKS   COLUMN_DEF   SQL_DATA_TYPE
   SQL_DATETIME_SUB   CHAR_OCTET_LENGTH   ORDINAL_POSITION   IS_NULLABLE   SS_DATA_TYPE

TestDB    dbo    CUSTOMERS   ID        4   int        10   4    0      10     0
   NULL   NULL   4   NULL    NULL      1   NO         56

TestDB    dbo    CUSTOMERS   NAME      12  varchar    20   20   NULL   NULL   0
   NULL   NULL   12   NULL   20        2   NO         39

TestDB    dbo    CUSTOMERS   AGE       4   int        10   4    0      10     0
   NULL   NULL   4   NULL    NULL      3   NO         56

TestDB    dbo    CUSTOMERS   ADDRESS   1   char       25   25   NULL   NULL   1
   NULL   NULL   1   NULL    25        4   YES        39

TestDB    dbo    CUSTOMERS   SALARY   3   decimal     18   20   2      10     1
   NULL   NULL   3   NULL    NULL     5   YES         106

CUSTOMERS 表在数据库中可用,因此让我们删除它。以下是相同的命令。

CUSTOMERS table is available in the database, so let us drop it. Following is the command for the same.

DROP TABLE CUSTOMERS;
Command(s) completed successfully.

使用以上命令,你将不会得到任何行。

With the above command, you will not get any rows.

Exec sp_columns CUSTOMERS;
No rows\data will be displayed