OpenSQL Reference Guide > OpenSQL Reference Guide > Extended Statements > CREATE TABLE (extended) > Column-Level Constraints and Table-Level Constraints
Was this helpful?
Column-Level Constraints and Table-Level Constraints
Constraints can be specified for:
Individual columns as part of the column specification (column-level constraints)
Groups of columns as part of the table definition (table-level constraints)
For example:
Column-level constraints:
create table mytable(name char(10) not null,
         id integer references idtable(id),
         age integer check (age > 0));
Table-level constraints:
create table yourtable(firstname char(20) not null,
         lastname char(20) not null,
         unique(firstname, lastname));
Note:  Multiple column constraints are separated by a space.
Names can be assigned to both column-level and table-level constraints. If the constraint name is omitted, the DBMS assigns one. To drop a constraint (using the ALTER TABLE statement), specify the constraint name. It is advisable to specify a name when creating a constraint; otherwise system catalogs must be queried to determine the name assigned by the DBMS when the constraint was created.
Last modified date: 08/28/2024