Primary key constraint primary key: a table can have only one primary key, the master key can not be empty, can not be repeated
Set primary key constraint: 1 when creating a table set up on the primary key constraint
create table person(id int primary key);
或 create table person(id int ,name char(10),primary key(id));
2 to set the primary key constraint by modifying the properties listed in the table of
alter table person add primary key(id);
或 alter table person modify id int primary key;
Set the primary key: 1: When it is set to create a primary key constraint
create table person(id int,name char(10),primary key(id,name));
2: Modify the column primary key constraint property
alter table person add primary key(id,name);
Primary key column values of different recording can not be simultaneously the same, it may be the same, can not be empty
Remove primary key constraint: alter table person drop primary key;
Increments constraint auto_increment: set to auto-increment columns, he did not add value to him, the system will automatically give him an assignment, usually the primary key constraint set increments
create table student(id int primary key auto_increment);
The only constraint unique: unique constraint set value can not be repeated
The only constraint set: 1 when creating tables to set up a unique constraint
create table person(id int unique);
或 create table person(id int ,name char(10),unique(id));
2 to set the unique attribute constraint by modifying the column in the table
alter table person add unique(id);
或 alter table person modify id int unique;
The only constraint is set jointly: 1: When creating a unique constraint is set for the joint
create table person(id int,name char(10),primary key(id,name));
2: Modify the column unique constraint property joint
alter table person add unique(id,name);
The only constraint combined column value different recording can not be simultaneously the same, may be the same, can not be empty
Remove primary key constraint: alter table person drop unique;
Default constraint default: Set the default value of a column in the absence of records
create table person (id int,name char(10) default 'zhangsan');
Non-empty constraint not null: not null constraint column values can not be empty
create table person(id int,name char(10) not null);
Foreign key constraint foreige key references: column value sub-table is selected from the main constraint constraint table column values, a column value master table when the constraint value by using the sub table column, the column value master table can not be deleted. Primary table must be the primary key column;
create table person(id int primary key);
create table student(id int,foreign key(id) references person(id));