--添加约束的语法
alter table 表名称 add constraint 约束名 约束类型 具体的约束说明
--主键约束
alter table stuinfo add constraint PK_Stuid_key primary key (stuid);
--唯一约束
alter table stuinfo add constraint PK_Stuid_unique unique (stuid);
--默认约束
alter table OrderInfo add constraint PK_SaLeDate_Defalut default(getdate()) for SaleDate;
--数据检查约束
alter table stuscore add constraint PK_Score_Check check(score>=0 and score<=100);
--外键约束
alter table stuscore add constraint PK_Score_ID foreign key(stuid) references stuinfo(stuid);
--校验长度
alter table stuinfo add constraint PK_Score_Check check(len(stuname)>=15 and len(stuname)<=18);
sql的约束汇总
最新推荐文章于 2021-07-27 09:41:14 发布