default 为列赋默认值 ,在Insert语句执行时检查。每个列只能有一个default约束,不能用于有Identity属性或rowversion数据类型的列
Alter Table dbo.Customer
Add
Constraint df_contactname DEFAULT 'UNKNOW' for ContactName
check 检查数据范围,在Insert和Update语句执行时检查。不能包括子查询,不能用于有rowversion数据类型的列。
Alter Table dbo.Employees
Add
Constraint ck_birthdate
Check (Birthdate > '01-01-1900' And Birthdate < getdate())
primary key 主关键字,行唯一标示符。不允许为空,总要创建一个索引。
Alter Table dbo.Customer
Add
Constraint pk_customer
Primary Key nonclustered (CustomerID)
unique 统一列中的两行不能有相同值。可以有空值,不能用于主关键字。
Alter Table dbo.Suppliers
Add
Constraint u_companyName
Unique nonclustered (CompanyName)
with Nocheck选项对现有数据约束检验失效