Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
primary key, you must specify the column names from the UNIQUE constraint
in the REFERENCES clause.
The ON UPDATE and ON DELETE clauses work as they do in a foreign
key column constraint: They specify what action, if any, will be taken to silently
repair constraint violations caused by update and delete operations performed
on the corresponding parent row. RESTRICT is the default; it produces an error
message and prevents the operation.
The CHECK ON COMMIT clause defers checking of this constraint until a
COMMIT is executed. This feature bends Rule 12 of relational databases, which
states it must not be possible to bypass the integrity rules or constraints when
manipulating the data. The FOREIGN KEY constraint isnt being bypassed
altogether; its application is simply being postponed.
CHECK ON COMMIT can help when it is inconvenient to make changes
in the correct order, (i.e., insert parents first, delete parents last, and so on).
An application can insert, delete, and update rows in any order it wants as long
as the FOREIGN KEY constraint is not violated when the changes are complete
and a COMMIT is issued.
The index automatically created on the foreign key columns may be
defined as CLUSTERED or NONCLUSTERED, with NONCLUSTERED
being the default. For more information about clustered indexes, see Section
10.7, CREATE INDEX.
INSERT t VALUES ( 1, 1, 1 ); -- OK
INSERT t VALUES ( 2, 1, 2 ); -- OK
INSERT t VALUES ( 3, 2, 1 ); -- OK
INSERT t VALUES ( 4, 1, 1 ); -- fails
The unique index automatically created on the UNIQUE constraint columns
may be defined as CLUSTERED or NONCLUSTERED, with
NONCLUSTERED being the default. For more information about clustered
indexes, see Section 10.7, CREATE INDEX.