previous | index | next

Foreign Key Constraints

If a DBMS vendor supports foreign key constraints, foreign keys can be used to maintain database integrity.

For example, suppose that a particular customer row is deleted:

   DELETE FROM customer WHERE id = 10;
Now, if another table, for example sales_order, has a column that refers to the deleted customer, that table will be corrupted.

In Apache Derby, if foreign keys are declared at table creation time, the above situation will be detected and the deletion will not be allowed to occur.

Here is the Order Table with Foreign Key Constraints.

Now, the above delete will be disallowed, while

   DELETE FROM customer WHERE id = 15;

will be allowed.


previous | index | next