|
The SQL syntax for ALTER TABLE Add Constraint is
ALTER TABLE "table_name"
ADD [CONSTRAINT_NAME] [CONSTRAINT_TYPE] [CONSTRAINT_CONDITION]
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 add a UNIQUE constraint to the "Address" column. To do this, we type in the following:
MySQL:
ALTER TABLE customer ADD CONSTRAINT con_first UNIQUE (first_name);
Oracle:
ALTER TABLE customer ADD CONSTRAINT con_first UNIQUE (first_name);
SQL Server:
ALTER TABLE customer ADD CONSTRAINT con_first UNIQUE (first_name);
where con_first is the name of the constraint.
ALTER TABLE DROP CONSTRAINT >>
Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.
Copyright © 2012 1keydata.com All Rights Reserved. Privacy Policy
|