sql server中有五种约束
使用sql语句创建和删除约束
主建约束:(primary key constraint);
外建约束:(foreign key
constraint);
唯一约束:(unique constraint);
检查约束:(check
constraint);
默认约束:(default constraint);
**********************************************************************
添加约束:
alter table tablename
add constraint pk_colname primary
key(colname)主建约束
alter table tablename
add constraint uq_colname unique
(colname)唯一约束
alter table tablename
add constraint df_colname
default(‘地址不详‘)for colname 默认约束
alter table tablename
add constraint
ck_colname check(colname between 12 and 15)检查约束
alter table tablename
add
constraint fk_colname foreign key(colname)references
tablename(colname)外建约束
删除约束:
alter table tablename
drop constraint 约束名