1.主键约束
【格式】alter table <表名> add constraint <约束名> primary key [clusterd | nonclustered] (<主键列名>)
2.外键约束
【格式】alter tabel <表名> add constraint <约束名> foreign key (<外键列名>) reference <父表名>(<主键列名>)
3.检查约束
【格式】alter table <表名> add constraint <约束名> check(<逻辑表达式>)
4.默认值约束
【格式】alter table <表名> add constraint <约束名> default 常量表达式 for <列名>
5.唯一性约束
【格式】alter table <表名> add constraint <约束名> unique[ clustered | nonclustered] (<列名>)
6.空值/非空值约束
【格式】alter table <表名> add constraint <约束名> check( <列名> is [ null | not null ])
本文详细介绍了SQL中六种常见的表约束:主键约束、外键约束、检查约束、默认值约束、唯一性约束及空值/非空值约束。通过具体的SQL语句格式展示如何在数据库表中应用这些约束。
850

被折叠的 条评论
为什么被折叠?



