SQL DROP 关键字
DROP COLUMN
The DROP COLUMN
command is used to delete a column in an existing table. (DROP COLUMN 命令用于删除现有表中的列。)
The following SQL deletes the "ContactName" column from the "Customers" table (以下 SQL 语句从 "Customers" 表中删除 "ContactName" 列)
示例
ALTER TABLE Customers
DROP COLUMN ContactName;
DROP a UNIQUE Constraint (删除 UNIQUE 约束)
To drop a UNIQUE constraint, use the following SQL (要删除 UNIQUE 约束,请使用以下 SQL 语句)
SQL Server / Oracle / MS Access
ALTER TABLE Persons
DROP CONSTRAINT UC_Person;
MySQL
ALTER TABLE Persons
DROP INDEX UC_Person;
DROP a PRIMARY KEY Constraint (删除 PRIMARY KEY 约束)
To drop a PRIMARY KEY constraint, use the following SQL (要删除 PRIMARY KEY 约束,请使用以下 SQL 语句)
SQL Server / Oracle / MS Access
ALTER TABLE Persons
DROP CONSTRAINT PK_Person;
MySQL
ALTER TABLE Persons
DROP PRIMARY KEY;
DROP a FOREIGN KEY Constraint (删除 FOREIGN KEY 约束)
To drop a FOREIGN KEY constraint, use the following SQL (要删除 FOREIGN KEY 约束,请使用以下 SQL 语句)
SQL Server / Oracle / MS Access
ALTER TABLE Orders
DROP CONSTRAINT FK_PersonOrder;
MySQL
ALTER TABLE Orders
DROP FOREIGN KEY FK_PersonOrder;
DROP a CHECK Constraint (删除 CHECK 约束)
To drop a CHECK constraint, use the following SQL (要删除 CHECK 约束,请使用以下 SQL 语句)
SQL Server / Oracle / MS Access
ALTER TABLE Persons
DROP CONSTRAINT CHK_PersonAge;
MySQL
ALTER TABLE Persons
DROP CHECK CHK_PersonAge;
DROP DEFAULT
The DROP DEFAULT
command is used to delete a DEFAULT constraint. (DROP DEFAULT 命令用于删除 DEFAULT 约束。)
To drop a DEFAULT constraint, use the following SQL (要删除 DEFAULT 约束,请使用以下 SQL 语句)
SQL Server / Oracle / MS Access
ALTER TABLE Persons
ALTER COLUMN City DROP DEFAULT;
MySQL
ALTER TABLE Persons
ALTER City DROP DEFAULT;
DROP INDEX
The DROP INDEX
command is used to delete an index in a table. (DROP INDEX 命令用于删除表中的索引。)
MS Access
DROP INDEX index_name ON table_name;
SQL Server
DROP INDEX table_name.index_name;
DB2/Oracle
DROP INDEX index_name;
MySQL
ALTER TABLE table_name
DROP INDEX index_name;
DROP DATABASE
The DROP DATABASE
command is used is to delete an existing SQL database. (DROP DATABASE 命令用于删除现有的 SQL 数据库。)
The following SQL drops a database named "testDB" (以下 SQL 语句删除名为 "testDB" 的数据库)
示例
DROP DATABASE testDB;
Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored in the database! (注意:删除数据库前请务必小心。删除数据库将导致其中存储的所有信息丢失!)
DROP TABLE
The DROP TABLE
command deletes a table in the database. (DROP TABLE 命令用于删除数据库中的表。)
The following SQL deletes the table "Shippers" (以下 SQL 语句删除 "Shippers" 表)
示例
DROP TABLE Shippers;
Note: Be careful before deleting a table. Deleting a table results in loss of all information stored in the table! (注意:删除表前请务必小心。删除表将导致其中存储的所有信息丢失!)
DROP VIEW
The DROP VIEW
command deletes a view. (DROP VIEW 命令用于删除视图。)
The following SQL drops the "Brazil Customers" view (以下 SQL 语句删除 "Brazil Customers" 视图)
示例
DROP VIEW [Brazil Customers];