Oracle 5.0 Reference Manual page 1062

Table of Contents

Advertisement

permits a foreign key to reference any index column or group of columns. However, in
InnoDB
the referenced table, there must be an index where the referenced columns are listed as the first
columns in the same order.
• Index prefixes on foreign key columns are not supported. One consequence of this is that
columns cannot be included in a foreign key because indexes on those columns must always
TEXT
include a prefix length.
• If the
CONSTRAINT symbol
database. If the clause is not given, or a
a name for the constraint is created automatically.
does not currently support foreign keys for tables with user-defined partitioning. This
InnoDB
includes both parent and child tables.
Referential Actions
This section describes how foreign keys help guarantee
For storage engines supporting foerign keys, MySQL rejects any
attempts to create a foreign key value in a child table if there is no a matching candidate key value in
the parent table.
When an
UPDATE
in the child table, the result depends on the referential action specified using
subclauses of the
DELETE
be taken, listed here:
• CASCADE: Delete or update the row from the parent table, and automatically delete or update the
matching rows in the child table. Both
supported. Between two tables, do not define several
same column in the parent table or in the child table.
NULL: Delete or update the row from the parent table, and set the foreign key column or
SET
columns in the child table to NULL. Both
clauses are supported.
If you specify a
table as
NOT
• RESTRICT: Rejects the delete or update operation for the parent table. Specifying
ACTION) is the same as omitting the
ACTION: A keyword from standard SQL. In MySQL, equivalent to RESTRICT. The MySQL
NO
Server rejects the delete or update operation for the parent table if there is a related foreign key
value in the referenced table. Some database systems have deferred checks, and
deferred check. In MySQL, foreign key constraints are checked immediately, so
same as RESTRICT.
DEFAULT: This action is recognized by the MySQL parser, but
SET
containing
For an
ON DELETE
MySQL supports foreign key references between one column and another within a table. (A column
cannot have a foreign key reference to itself.) In these cases, "child table records" really refers to
dependent records within the same table.
CREATE TABLE
clause is given, the
or
operation affects a key value in the parent table that has matching rows
DELETE
FOREIGN KEY
Note
Currently, cascaded foreign key actions do not activate triggers.
action, make sure that you have not declared the columns in the child
SET NULL
NULL.
ON DELETE SET DEFAULT
or
that is not specified, the default action is always RESTRICT.
ON UPDATE
Syntax
value, if used, must be unique in the
symbol
is not included following the
symbol
referential
clause. MySQL supports five options regarding the action to
ON DELETE CASCADE
ON UPDATE CASCADE
ON DELETE SET NULL
or
ON DELETE
ON UPDATE
or
ON UPDATE SET DEFAULT
1042
CONSTRAINT
integrity.
or
operation that
INSERT
UPDATE
ON UPDATE
and
ON UPDATE CASCADE
clauses that act on the
and
ON UPDATE SET NULL
RESTRICT
clause.
NO ACTION
NO ACTION
rejects table definitions
InnoDB
clauses.
and
BLOB
keyword,
and
ON
are
(or
NO
is a
is the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents