Mysql database learning-4, integrity constraints bitsCN.com
Mysql database learning-4, integrity constraints
Primary key
create table feng(teamno int not null,playerno int not null,pision char(6) not null,primary key(teamno))create table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,)
Composite primary key
create table feng(teamno int not null,playerno int not null,pision char(6) not null,primary key(teamno,playerno))
Alternative Key (candidate key)
create table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,unique(playerno))create table feng(teamno int not null primary key ,playerno int not null,pision char(6) not null,unique(playerno,pision))
Foreign key (used in innoDB)
The foreign key Declaration consists of three parts:
1. the column or column combination is a foreign key
2. specify tables and columns for foreign key reference
3. for details, refer to [cascade (cascade operation), restrict (reject operation), set null (set to null), no action, set default].
If no reference action is specified, the default value is
On update restricton delete restrictcreate table feng (teamno int not null primary key, playerno int not null, pision char (6) not null, foreign key (pision) references othertable (column) on update restrictunique (playerno) check integrity constraint create table players (playerno int not null, sex char (1) not null, check (sex in ('M ', 'F') create table players (playerno int not null, birth_date date, sex char (1) not null, check (sex in ('M', 'F ')) joined smallint not null, check (year (birth_date)
BitsCN.com