MySQL PRIMARY KEY FOREIGN key

Source: Internet
Author: User

Cartesian product

Multi-table query, multiple tables become a table

Integrity constraint conditions
Primary key identifies this property as the primary key for the table and can uniquely identify the corresponding tuple
Foreign key identifies this property as a foreign key of the table, and is the primary key of a table associated with it
Not NULL identifies the property cannot be empty
Unique identifies the value of the property as distinct
Auto_increment identifies the value of this property automatically increases
Default defaults for this property
Set the foreign key from the table
Constraint foreign key alias foreign Key (attribute 1.1, Property 1.2, ..., attribute 1.N)
References table name (property 2.1, Property 2.2, ..., attribute 2.N)
To add a Slave key constraint
ALTER TABLE Empl
Add foreign Key Empl (e_id) reference depart (d_id);

You can set the primary key foreign key (FOREIGN KEY constraint) when you create the table.
Primary key
Column name type primary key auto_increment,
From the key
Constraint foreign key alias foreign Key (attribute 1.1, Property 1.2, ..., attribute 1.N) reference the primary table name (attribute 2.1, Property 2.2, ..., attribute 2.N);

FOREIGN KEY constraints
CREATE TABLE Dept (
did int primary key auto_increment,
Dname varchar (10)
);

CREATE TABLE EMP (
Eid int primary Key auto_increment,
Name varchar (10),
DNO int,
FOREIGN key EMP (DNO) References Dept (did)
);

MySQL PRIMARY KEY FOREIGN key

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.