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