Oracle 5.0 Reference Manual page 49

Table of Contents

Advertisement

1.8.6.2.
FOREIGN KEY
Foreign keys let you cross-reference related data across tables, and
this spread-out data consistent.
MySQL supports
statements. The available referential actions are
TABLE
and
NO
ACTION.
SET DEFAULT
Since MySQL does not support deferred constraint checking,
the exact syntax supported by MySQL for foreign keys, see
Constraints".
MATCH
FULL,
as they cause the MySQL Server to ignore any
statement.
MATCH
semantics full-time.
SIMPLE
MySQL requires that foreign key columns be indexed; if you create a table with a foreign key constraint
but no index on a given column, an index is created.
You can obtain information about foreign keys from the
table. An example of a query against this table is shown here:
mysql>
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME
>
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
>
WHERE REFERENCED_TABLE_SCHEMA IS NOT NULL;
+--------------+---------------+-------------+-----------------+
| TABLE_SCHEMA | TABLE_NAME
+--------------+---------------+-------------+-----------------+
| fk1
| fk1
| fk1
+--------------+---------------+-------------+-----------------+
3 rows in set (0.01 sec)
Information about foreign keys on
INNODB_SYS_FOREIGN_COLS
Currently, only
Constraints", for information specific to foreign key support in InnoDB.
Deviations from SQL Standards
MySQL's implementation of foreign keys differs from the SQL standard in the following key respects:
• If there are several rows in the parent table that have the same referenced key value,
in foreign key checks as if the other parent rows with the same key value do not exist. For example,
if you have defined a
does not permit the deletion of any of those parent rows.
InnoDB
performs cascading operations through a depth-first algorithm, based on records in the
InnoDB
indexes corresponding to the foreign key constraints.
• A
FOREIGN KEY
extension.
InnoDB
• If
ON UPDATE CASCADE
previously updated during the same cascade, it acts like RESTRICT. This means that you cannot
use self-referential
infinite loops resulting from cascaded updates. A self-referential
How MySQL Deals with Constraints
Constraints
and
ON UPDATE
ON DELETE
is also supported by the MySQL Server but is currently rejected as invalid by InnoDB.
PARTIAL, and
MATCH
options do not have any other effect in MySQL, which in effect enforces
| COLUMN_NAME | CONSTRAINT_NAME |
| myuser
| myuser_id
| product_order | customer_id | f2
| product_order | product_id
InnoDB
tables, in the
tables support foreign keys. See
InnoDB
type constraint, and there is a child row with several parent rows,
RESTRICT
constraint that references a
or
ON UPDATE SET NULL
ON UPDATE CASCADE
foreign key references in
RESTRICT
Section 13.1.10.2, "Using
are allowed, but their use should be avoided,
MATCH SIMPLE
or
ON DELETE
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
| f
| f1
tables can also be found in the
INFORMATION_SCHEMA
Section 14.2.3.4,
non-UNIQUE
recurses to update the same table it has
or
ON UPDATE SET NULL
29
foreign key constraints
CREATE TABLE
(the default), CASCADE,
is treated as RESTRICT. For
NO ACTION
clause used in the same
ON UPDATE
|
|
|
INNODB_SYS_FOREIGN
database.
"InnoDB
and
key is not standard SQL but rather an
operations. This is to prevent
ON DELETE SET
help keep
and
ALTER
SET
NULL,
FOREIGN KEY
MATCH
and
FOREIGN KEY
acts
InnoDB
NULL, on the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents