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];