Previous Topic

Next Topic

Table-Level Candidate Key Constraint

If an application requires that the values for a combination of columns be unique, then the candidate key specification is to be done at the table level. For example, in an order_item table the columns order_no and item_no together form a unique key.

Consider the following example:

CREATE TABLE order_item (
     order_no    INTEGER NOT NULL,
     item_no     INTEGER NOT NULL,
     qty         INTEGER,
     price       MONEY
     UNIQUE (order_no, item_no)
) ;

In the above example, the combination of columns order_no and item_no is the unique identifier of the table order_item.