The DROP COLUMN command removes a column from an existing table.
The provided SQL statement deletes the “ContactName” column from the “Customers” table.
ALTER TABLE Customers DROP COLUMN ContactName; |
To remove a UNIQUE constraint, employ the following SQL statement:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons DROP CONSTRAINT UC_Person; |
MySQL:
ALTER TABLE Persons DROP INDEX UC_Person; |
To remove a PRIMARY KEY constraint, execute the following SQL statement:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons DROP CONSTRAINT PK_Person; |
MySQL:
ALTER TABLE Persons DROP PRIMARY KEY; |
To eliminate a FOREIGN KEY constraint, utilize the following SQL statement:
SQL Server / Oracle / MS Access:
ALTER TABLE Orders DROP CONSTRAINT FK_PersonOrder; |
MySQL:
ALTER TABLE Orders DROP FOREIGN KEY FK_PersonOrder; |
To remove a CHECK constraint, execute the following SQL statement:
SQL Server / Oracle / MS Access:
ALTER TABLE Persons DROP CONSTRAINT CHK_PersonAge; |
MySQL:
ALTER TABLE Persons DROP CHECK CHK_PersonAge; |
The DROP DEFAULT command removes a DEFAULT constraint.
To eliminate a DEFAULT constraint, execute the following SQL statement:
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 employed to remove 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 table_name DROP INDEX index_name; |
The DROP DATABASE command is used to delete an existing SQL database.
The provided SQL drops a database named “testDB”.
DROP DATABASE testDB; |
Caution: Exercise caution before dropping a database. Deleting a database will lead to the loss of all information stored within it! |
The DROP TABLE command eliminates a table from the database.
The subsequent SQL statement removes the “Shippers” table:
DROP TABLE Shippers; |
Caution: Exercise care prior to deleting a table. Deleting a table leads to the loss of all data stored within it! |
The DROP VIEW command removes a view.
The following SQL drops the “Brazil Customers” view:
DROP VIEW [Brazil Customers]; |