#域完整性
类型约束
非空约束 不能为空 not null
默认值 default '0'
#非空和默认值
create table student(
sid int primary key auto_increment,
sname varchar(20) not null,
gender bit(1) default 1
);
desc class
#引用完整性
一张表中通用列的取值必须参考另一张表主键字段
student {
uid 编号 primary key
uname 姓名
}
class{
cid 班级编号
cname 班级名称
}
alter table student drop cid;
alter table student add cid int
desc student
#添加外键,必须先添加字段,才能添加外键约束,外键关联字段名称可以不一样,类型必须一样
alter table student Add constraint FK_CID foreign key(cid)
references class(cid)
MySQL进阶之路三(其他类型约束)
猜你喜欢
转载自blog.csdn.net/ZhaiAlan/article/details/92770980
今日推荐
周排行