Create foreign keys in mysql_PHP tutorial

WBOY
Release: 2016-07-21 15:59:50
Original
909 people have browsed it

Prerequisite for establishing a foreign key: The columns of this table must be of the same type as the foreign key (the foreign key must be the primary key of the table).
Function of foreign keys: To associate two tables. Foreign keys can only refer to the values ​​of columns in the table!
Specify the primary key keyword: foreign key (column name)
Quote the foreign key keyword: references (foreign key column name)
Event triggering restrictions: on delete and on update , you can set parameters cascade (follow foreign key changes), restrict (restrict foreign key changes in the table), set Null (set null value), set Default (set default value), [default] no action
For example:
outTable table primary key id type int
Create a table with foreign keys:
create table temp(
id int,
name char(20),
foreign key(id) references outTable (id) on delete cascade on update cascade);
Explanation: Set the id column as a foreign key. Refer to the id column of the outer table outTable. When the value of the foreign key is deleted, the corresponding column in this table is filtered. When the value of the foreign key changes, this The corresponding column value in the table changes.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317248.htmlTechArticlePrerequisite for establishing a foreign key: The columns of this table must be of the same type as the foreign key (the foreign key must be the primary key of the foreign key) . The function of foreign keys: to associate two tables, foreign keys can only reference the values ​​of columns in the table! Refers to...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!