Professional Documents
Culture Documents
the child column to its DEFAULT value, one which presumably matches some
other row in the parent table.
The ON DELETE clause says that when a parent row is deleted, one of
three actions will be taken with all the corresponding child rows. ON DELETE
CASCADE eliminates the violation in a brute-force fashion by deleting all the
corresponding child rows. ON DELETE SET NULL changes the child column
to NULL so it no longer violates the constraint. ON DELETE SET DEFAULT
changes the child column to its DEFAULT value, one which matches some
other row in the parent table that hasnt been deleted yet.
All these repairs are made silently, with no error messages. There is a
fourth choice in each case: ON UPDATE RESTRICT and ON DELETE
RESTRICT are the default actions, which produce an error message and prevent
the operation on the parent table.
For performance reasons an index is created for every foreign key con-
straint, so you dont have to define the index yourself. This index may be
defined as CLUSTERED or NONCLUSTERED, with NONCLUSTERED
being the default. For more information about clustered indexes, see Section
10.7, CREATE INDEX.