`

sql 约束大全

SQL 
阅读更多
--------添加主键约束(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 约束名

--
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics