Adding and removing constraints

 

Constraints can be added to a new table or to an existing table. To add a unique or primary key, a referential constraint, or a check constraint, use the CREATE TABLE or the ALTER TABLE statement. To remove a constraint, use the ALTER TABLE statement.

For example, add a primary key to an existing table using the ALTER TABLE statement:

ALTER TABLE CORPDATA.DEPARTMENT         
  ADD PRIMARY KEY (DEPTNO)

To make this key a unique key, replace the keyword PRIMARY with UNIQUE.

You can remove a constraint using the same ALTER TABLE statement:

ALTER TABLE CORPDATA.DEPARTMENT         
  DROP PRIMARY KEY (DEPTNO)

 

Parent topic:

Creating a table