主键约束

 

--------添加主键约束(bookid作为主键)

alter table bookmessage

add constraint pk_bookid primary key(bookid)

 

--------添加唯一约束

alter table bookmessage

add constraint uq_bookid UNIQUE(bookid)

 

---------添加默认约束

alter table bookmessage

add constraint df_address DEFAUIT('地址不详') for Address

 

--------添加检出约束,要求年龄只能在15---40之间

alter table readermessage

add constraint CK_age CHECK(age BETWEEN 15 AND 40)

 

-------添加外键约束

alter table bookmessage

add constraint fk_bookid

foreign key(bookid)<外键> references readermessage<>(readerid)<表中的主键>

 

-------删除约束

alter table 表名

drop constraint 约束名

 

 

查看表的约束名执行

 

sp_helpconstraint 表名

 

第二个结果集就列出了表的约束,constraint_name就是约束名

posted @ 2009-12-24 11:46  tangself  阅读(253)  评论(0编辑  收藏  举报