Previous Topic

Next Topic

Table-Level Foreign Key Constraint

If a foreign key constraint specification involves more than one column, then the constraint is to be specified at the table level.

Consider the following example:

CREATE TABLE hours_worked (
     empno       INTEGER NOT NULL,
     projno      INTEGER NOT NULL,
     date        DATE,
     hours       TIME
     FOREIGN KEY (empno, projno)
     REFERENCES assignments (empno, projno)
) ;

In this example, the foreign key (empno, projno) of table hours_worked, references the primary/candidate key (empno, projno) of table assignments. Since the foreign key involves more than one column, it is defined at the table level.