Add Clause: Constraints
- Last Updated: May 15, 2020
- 1 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Purpose
Adds a constraint to an existing table. It is optional.
Syntax
ADD [CONSTRAINT constraint_name] ...
Notes
- The only type of constraint you can add is a foreign key constraint.
- When adding a foreign key constraint, the table that contains the foreign key must be empty.
Example
Assuming the current schema is SFORCE, a foreign key constraint is added to the
deptId column of the test table, referencing the
rowId of the dept table. For the operation to succeed,
the dept table must be empty.
ALTER TABLE test ADD FOREIGN KEY (deptId) REFERENCES dept(rowId)