SQL > ALTER TABLE > Drop Constraint Syntax

Constraints can be placed on a table to limit the type of data that can go into a table. Since we can specify constraints on a table, there needs to be a way to remove this constraint as well. In SQL, this is done via the ALTER TABLE statement.

The SQL syntax to remove a constraint from a table is,

ALTER TABLE "table_name"
DROP [CONSTRAINT|INDEX] "CONSTRAINT_NAME";

Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:

Table Customer

Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedatetime

Assume we want to drop the UNIQUE constraint on the "Address" column, and the name of the constraint is "Con_First." To do this, we type in the following:

MySQL:

ALTER TABLE Customer DROP INDEX Con_First;

Note that MySQL uses DROP INDEX for index-type constraints such as UNIQUE.

Oracle:

ALTER TABLE Customer DROP CONSTRAINT Con_First;

SQL Server:

ALTER TABLE Customer DROP CONSTRAINT Con_First;

Next: SQL NULL




Copyright © 2014   1keydata.com   All Rights Reserved.     Privacy Policy