Prerequisites for creating a MYSQL foreign key

Source: Internet
Author: User

The following articles mainly refer to the definition of MYSQL Foreign keys and the prerequisites for establishing MYSQL Foreign keys, that is, the related columns of the table must belong to the same type as the foreign key (the foreign key must be the external primary key. We all know that foreign keys are used to associate two tables. Foreign keys can only reference the values of columns in the External table!

Specify the primary key Keyword: foreign key (column name)

Reference MYSQL key keywords: 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 sets the Default value), [Default] no action

For example:

OutTable table primary key id type int

Create a table with foreign keys:

 
 
  1. Create table temp (
  2. Id int,
  3. Name char (20 ),
  4. Foreign key (id) references outTable (id) on delete cascade on update cascade );


The above content is an introduction to the MYSQL foreign key. I hope you will get some benefits.

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.