要用查询分析器写约束却忘记了,记一笔备忘
主键约束:
alter table transInfo[主表]
add constraint PK_UID[主键约束名称] primary key (UID)[主表字段]
主外键约束:
alter table transInfo[主表] add constraint
FK_cardID[主外键约束名称] foreign key (cardID)[主表字段] references cardInfo(cardID)[从表(从表字段)]
唯一约束:
alter table transInfo[主表]
add constraint UQ_A_AdPlace[唯一约束名称] unique (A_AdPlace) [主表字段]
检查约束:
alter table transInfo[主表] add constraint
CK_transMoney[检查约束名称] check (transMoney[主表字段]>0)
默认约束:
alter table transInfo[主表] add constraint
DF_transDate[默认约束名称] default (getdate()[默认的条件]) for transDate[主表字段]