Rechercher dans le manuel MySQL
1.8.3.2 FOREIGN KEY Constraints
Foreign keys let you cross-reference related data across tables, and foreign key constraints help keep this spread-out data consistent.
MySQL supports ON UPDATE
and ON
DELETE
foreign key references in
CREATE TABLE
and
ALTER TABLE
statements. The
available referential actions are RESTRICT
(the default), CASCADE
, SET
NULL
, and NO ACTION
.
SET DEFAULT
is also supported by the MySQL
Server but is currently rejected as invalid by
InnoDB
. Since MySQL does not
support deferred constraint checking, NO
ACTION
is treated as RESTRICT
.
For the exact syntax supported by MySQL for foreign keys, see
Section 13.1.20.6, “Using FOREIGN KEY Constraints”.
MATCH FULL
, MATCH
PARTIAL
, and MATCH SIMPLE
are
allowed, but their use should be avoided, as they cause the
MySQL Server to ignore any ON DELETE
or
ON UPDATE
clause used in the same
statement. MATCH
options do not have any
other effect in MySQL, which in effect enforces MATCH
SIMPLE
semantics full-time.
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
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
table. An example of a query against this table is shown here:
- > FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
- +--------------+---------------+-------------+-----------------+
- | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME |
- +--------------+---------------+-------------+-----------------+
- | fk1 | myuser | myuser_id | f |
- | fk1 | product_order | customer_id | f2 |
- | fk1 | product_order | product_id | f1 |
- +--------------+---------------+-------------+-----------------+
Information about foreign keys on InnoDB
tables can also be found in the
INNODB_FOREIGN
and
INNODB_FOREIGN_COLS
tables, in
the INFORMATION_SCHEMA
database.
InnoDB
and NDB
tables
support foreign keys. See
Section 15.6.1.5, “InnoDB and FOREIGN KEY Constraints”, for
information specific to foreign key support in
InnoDB
.
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-constraint-foreign-key.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.