sql各种约束

来源:互联网 发布:2016复杂网络大会 编辑:程序博客网 时间:2024/05/19 12:15

--------添加主键约束(stuNo作为主键)
alter table stuInfo
add constraint PK_stuNo primary key(stuNo)
 
--------添加唯一约束
alter table stuInfo
add constraint UQ_stuID UNIQUE(stuID)
 
---------添加默认约束
alter table stuInfo
add constraint DF_stuAddress DEFAUIT('地址不详') for stuAddress
 
--------添加检出约束,要求年龄只能在15---40之间
alter table stuInfo
add constraint CK_stuAge CHECK(stuAge BETWEEN 15AND 40)
 
-------添加外键约束
alter table stuMarks
 add constraint FK_stuNo
  foreign key(stuNo)<外键> references stuInfo<表>(stuNo)<表中的主键> 
 
-------删除约束
alter table 表名
 drop constraint 约束名

原创粉丝点击