SQL Tutorial SQL Advanced SQL Database SQL References

SQL DROP CONSTRAINT Keyword



The SQL DROP CONSTRAINT statement is used to delete a UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK or DEFAULT constraint.

DROP a UNIQUE Constraint

To drop UC_Employee UNIQUE constraint from table called Employee, the below mentioned SQL code can be used:

MySQL

ALTER TABLE Employee
DROP INDEX UC_Employee;

MySQL / SQL Server / Oracle / MS Access

ALTER TABLE Employee
DROP CONSTRAINT UC_Employee;

DROP a PRIMARY KEY Constraint

To drop PK_Employee PRIMARY KEY constraint from table called Employee, the SQL code is given below:

MySQL / Oracle

ALTER TABLE Employee
DROP PRIMARY KEY;

SQL Server / Oracle / MS Access

ALTER TABLE Employee
DROP CONSTRAINT PK_Employee;

DROP a FOREIGN KEY Constraint

To drop FK_Contact_Info FOREIGN KEY constraint from table called Contact_Info, the SQL code is given below:

MySQL

ALTER TABLE Contact_Info
DROP FOREIGN KEY FK_Contact_Info;

MySQL / SQL Server / Oracle / MS Access

ALTER TABLE Contact_Info
DROP CONSTRAINT FK_Contact_Info;

DROP a CHECK Constraint

To drop CHK_Employee CHECK constraint from table called Employee, the SQL code is given below:

MySQL

ALTER TABLE Employee
DROP CHECK CHK_Employee;

MySQL / SQL Server / Oracle / MS Access

ALTER TABLE Employee
DROP CONSTRAINT CHK_Employee;

DROP a DEFAULT Constraint

To drop DEFAULT constraint from table called Employee, the SQL code is given below:

MySQL

ALTER TABLE Employee
ALTER City DROP DEFAULT;

OR

ALTER TABLE Employee
ALTER COLUMN City DROP DEFAULT;

SQL Server

/* Drops a DEFAULT constraint named DV_City */
ALTER TABLE Employee
DROP CONSTRAINT DV_City;

Oracle

ALTER TABLE Employee 
MODIFY City DEFAULT NULL;

❮ SQL Keywords