You can use the Control Center or the ALTER TABLE statement
to add unique keys.
About this task
Unique
constraints can be added to an existing table. The constraint name
cannot be the same as any other constraint specified within the ALTER
TABLE statement, and must be unique within the table (this includes
the names of any referential integrity constraints that are defined).
Existing data is checked against the new condition before the statement
succeeds.
Procedure
To add unique constraints using the Control Center:
- Open the Alter Table notebook:
- From the Control Center, expand the object tree until
you find the Tables folder.
- Click the Tables folder. Any existing tables are displayed in the pane on the right
side of the window.
- Right-click the table you want and select Alter from
the pop-up menu. The Alter Table notebook
opens.
- On the Check Constraints page, click Add.
- On the Add Check Constraint window,
complete the necessary information.
Example
To define dimensions using the command line, use the ADD
CONSTRAINT option of the ALTER TABLE statement. For example, the following
SQL statement adds a unique constraint to the EMPLOYEE table that
represents a new way to uniquely identify employees in the table:
ALTER TABLE EMPLOYEE
ADD CONSTRAINT NEWID UNIQUE(EMPNO,HIREDATE)