|
Constraint 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 for ALTER TABLE Drop Constraint 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 Name | Data Type |
| First_Name | char(50) |
| Last_Name | char(50) |
| Address | char(50) |
| City | char(50) |
| Country | char(25) |
| Birth_Date | date |
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 DROP TABLE
|
| Copyright © 2013 1keydata.com All Rights Reserved.
Privacy Policy |
|