主鍵create table feng(
teamno int not null,playerno int not null,division char(6) not null,primary key(teamno))
create table feng(
teamno int not null primary key ,playerno int not null,division char(6) not null,) 複合主鍵create table feng(
teamno int not null,playerno int not null,division char(6) not null,primary key(teamno,playerno)) 替代鍵(候選索引鍵) create table feng(
teamno int not null primary key ,playerno int not null,division char(6) not null,unique(playerno)) create table feng(
teamno int not null primary key ,playerno int not null,division char(6) not null,unique(playerno,division)) 外鍵(在innoDB中使用)外鍵聲明包括三個部分1,那個列或列組合是外鍵2,指定外鍵參照的表和列3,參照動作[cascade(級聯操作),restrict(拒絕操作),set null(設為空白),no action,set default]如果沒有指定參照動作預設是on update restricton delete restrictcreate table feng(
teamno int not null primary key ,playerno int not null,division char(6) not null,foreign key(division)references othertable (column)on update restrictunique(playerno)) check完整性條件約束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)<joined), check (joined<1880),) create table players (playerno int not null,birth_date date, sex char(1) not null, check (sex in (select sex from wholetab))