AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL Add Constraint Syntax |
SQL > ALTER TABLE >
Add Constraint Syntax
Sometimes we may decide to add a new constraint to an existing table (to see what are the different types of constraints that can be placed on a database table, please refer to the CONSTRAINT section). The syntax for adding a constraint in SQL 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
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 (Address);
Oracle:
ALTER TABLE Customer ADD CONSTRAINT Con_First UNIQUE (Address);
SQL Server:
ALTER TABLE Customer ADD CONSTRAINT Con_First UNIQUE (Address);
where Con_First is the name of the constraint. |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.