赞
踩
primary key
#primary key用例
create table world.city(id int primary key);
create table world.city(id int, primary key(id));
create table world.city(id int, name char(35), primary key(id, name));
foreign key
#foreign key用例
create table world.country(code char(3), name char(52), PRIMARY KEY (code));
create table world.city(id int AUTO_INCREMENT, countrycode char(3), PRIMARY KEY (id), foreign key(countrycode) references world.country (code));
not null
#not null用例
create table world.city(id int not null);
unique
NULL
表示没有值,因此即使有唯一性约束,一个字段也可以有多个NULL#unique用例
create table world.city(id int unique);
auto_increment
default
#default用例
create table world.city(id int default null);
#增加约束
alter table 表名 add constraint 约束名 primary key|foreign key|unique (列名);
#删除约束
alter table 表名 drop primary key;
alter table 表名 drop index 约束名;
#修改约束,修改后会消除原有约束,更新为设置的约束
alter table modify 列名 列类型 auto_increment|not null|default;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。