Mysql foreign key _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Create a foreign key for mysql. Prerequisites for creating a foreign key: the columns in the table must be of the same type as the foreign key (the foreign key must be the external primary key ). Foreign key: associate two tables. a foreign key can only reference the values of columns in the external table! The premise of creating a foreign key: the columns in the table must be of the same type as the foreign key (the foreign key must be the external primary key ).
Foreign key: associate two tables. a foreign key can only reference the values of columns in the external table!
Specify the primary key keyword: foreign key (column name)
Reference foreign key keyword: references <Foreign key table name> (Foreign key column name)
Event trigger restrictions: on delete and on update. you can set the parameters cascade, restrict, and set Null ), 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 );
Note: set the id column as the foreign key reference external table id column as the foreign key value delete this table corresponding to the column sieve when the foreign key value changes the corresponding column value in this table.

Foreign (the foreign key must be the external primary key ). Foreign key: associate two tables. a foreign key can only reference the values of columns in the external table! ...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.