Show 13.1.17.5 FOREIGN KEY ConstraintsMySQL supports foreign keys, which permit cross-referencing related data across tables, and foreign key constraints, which help keep the related data consistent. A foreign key relationship involves a parent table that holds the initial column values, and a child table with column values that reference the parent column values. A foreign key constraint is defined on the child table. The essential syntax for a defining a foreign key constraint in a
Foreign key constraint usage is described under the following topics in this section:
IdentifiersForeign key constraint naming is governed by the following rules:
Table and column identifiers in a Conditions and RestrictionsForeign key constraints are subject to the following conditions and restrictions:
For information about how the MySQL implementation of foreign key constraints differs from the SQL standard, see Section 1.7.2.3, “FOREIGN KEY Constraint Differences”. Referential Actions
When an
For storage engines that support foreign keys, MySQL rejects any
For an For As of NDB 7.3.25 and NDB 7.4.24: For Foreign Key Constraint Examples This simple example relates
This is a more complex example in which a
Adding Foreign Key Constraints You can add a foreign key constraint to an existing table using the following
The foreign key can be self referential (referring to the same table). When you add a foreign key constraint to a table using
Dropping Foreign Key Constraints You can drop a foreign key constraint using the following
If the
Adding and dropping a foreign key in the same Foreign Key Checks In MySQL, InnoDB and NDB tables support checking of
foreign key constraints. Foreign key checking is controlled by the The Disabling foreign key checking is useful when:
When
Disabling
Foreign Key Definitions and Metadata To
view a foreign key definition, use
You can obtain information about foreign keys from the
You can obtain information specific to
Foreign Key Errors In the event of a foreign key error involving
Warning
Apa itu Foreign Key pada MySQL?Pada bahasa pemrograman database SQL, seperti PHPMyAdmin, foreign key merupakan field dari sebuah tabel database yang bergantung pada field database lain.
Apa itu foreign key dalam database?Dalam SQL database sistem manajamen, foreign key adalah pengenal unik atau kombinasi pengenal unik yang menghubungkan dua tabel atau lebih dalam suatu database. Foreign key juga sering disebut sebagai kunci asing.
Bagaimana cara membuat primary key?Di Perancang 'Tabel': klik pemilih baris untuk kolom database yang ingin kamu tetapkan sebagai 'primary key'. Jika kamu ingin memilih beberapa kolom, tahan tombol 'CTRL' sambil mengklik pemilih baris untuk kolom lainnya. Klik kanan pemilih baris untuk kolom dan pilih Setel 'Primary Key'.
Apa itu primary key pada MySQL?Fungsi Primary Key pada MySQL
Kunci utama memungkinkan kamu untuk mengidentifikasi setiap baris di tabel. Hal ini penting dilakukan karena dapat menautkan tabel ke tabel lain yang berkaitan dengan kunci utama sebagai tautannya.
|