English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The DROP COLUMN command is used to delete a column from an existing table.
The following SQL deletes the 'ContactName' column from the 'Customers' table:
ALTER TABLE Customers DROP COLUMN ContactName;
To delete a UNIQUE constraint, use the following SQL:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons DROP CONSTRAINT UC_Person;
MySQL:
ALTER TABLE Persons DROP INDEX UC_Person;
To delete a PRIMARY KEY constraint, use the following SQL:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons DROP CONSTRAINT PK_Person;
MySQL:
ALTER TABLE Persons DROP PRIMARY KEY;
To delete a FOREIGN KEY constraint, use the following SQL:
SQL Server / Oracle / MS Access:
ALTER TABLE Orders DROP CONSTRAINT FK_PersonOrder;
MySQL:
ALTER TABLE Orders DROP FOREIGN KEY FK_PersonOrder;
To delete a CHECK constraint, use the following SQL:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons DROP CONSTRAINT CHK_PersonAge;
MySQL:
ALTER TABLE Persons DROP CHECK CHK_PersonAge;
The DROP DEFAULT command is used to delete a DEFAULT constraint.
To delete a DEFAULT constraint, use the following SQL:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons ALTER COLUMN City DROP DEFAULT;
MySQL:
ALTER TABLE Persons ALTER City DROP DEFAULT;
The DROP INDEX command is used to delete an index from a table.
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 DROP INDEX;
The DROP DATABASE command is used to delete an existing SQL database.
The following SQL deletes the database named 'testDB':
DROP DATABASE testDB;
Note:Be careful before deleting a database. Deleting a database will result in the loss of all information stored in the database!
The DROP TABLE command will delete a table from the database.
The following SQL deletes the table "Shippers":
DROP TABLE Shippers;
Note:Be careful before deleting a table. Deleting a table will result in the loss of all information stored in the table!
The DROP VIEW command will delete a view.
The following SQL deletes the 'Brazil Customers' view:
DROP VIEW [Brazil Customers];