--------------------------------
---------约束操作---------------
--------------------------------
--添加主键约束
alter table stuInfo
add constraint pk_stuNo primary key (stuNo)
go
--添加唯一约束
alter table stuInfo
add constraint uq_stuID unique (stuID)
go
--添加默认约束
alter table stuInfo
add constraint df_stuAddress default ('地址不详') for stuAddress
go
--添加check约束
alter table stuInfo
add constraint ck_stuAge check(stuAge between 15 and 40)
go
--添加外键约束(主表是stuInfo,外表是stuMarks)
alter table stuMarks
add constraint fk_stuNO
foreign key (stuNo) references stuInfo(stuNo)
go
--删除约束
alter table stuInfo
drop constraint pk_stuNo
go
alter table stuInfo
drop constraint uq_stuID
go
alter table stuInfo
drop constraint df_stuAddress
go
alter table stuInfo
drop constraint ck_stuAge
go
alter table stuMarks
drop fk_stuNo
go
sql 约束(constraint)
最新推荐文章于 2022-08-08 09:49:16 发布