’‘’
# not null default (不为空,设置默认值)
create table t1(x int not null);
insert into t1 values(); --报错,提示没有默认值
create table t2(x int not null default 111);
insert into t2 values(); --不报错,设为默认值
# unique (单列唯一)
create table t3(name varchar(10) unique);
# unique(*,*) (联合唯一)
create table server(
id int,
name varchar(10),
ip varchar(15),
port int,
unique(ip,port) --ip和port联合唯一
);
insert server values(1,"oldboy","127.0.0.1","8080");
insert server values(2,"oldgirl","127.0.0.1","8081");
# not null 和 unique的化学反应 会被识别成主键
create table t4(id int,name varchar(10) not null unique);∂
create table t5(id int,name varchar(10) unique);∂
# 主键 primary key
create table t6(
id int primary key auto_increment, --设为自增长
name varchar(10),
);
# 联合主键 primary key(id,name)
‘’‘
104 约束条件
猜你喜欢
转载自blog.csdn.net/qq_40808228/article/details/108369478
今日推荐
周排行