SqlServer禁用启用触发器、外键约束
--启用or禁用指定表所有外键约束 alter table tbname NOCHECK constraint all alter table tbname CHECK constraint all --查看约束 select name , is_disabled from sys.foreign_keys order by name --禁用 ALTER TABLE tbname DISABLE TRIGGER trigname --恢复 ALTER TABLE tbname ENABLE TRIGGER trigname --禁用某个表上的所有触发器 ALTER TABLE tbname DISABLE TRIGGER all --启用某个表上的所有触发器 ALTER TABLE tbname ENABLE TRIGGER all
--添加主键 alter table tbname add constraint pk_name primary key(column1,column2) --添加非聚集主键 alter table tbname add constraint pk_name primary key NONCLUSTERED(column1,column2) --删除主键 alter table tbname drop constraint pk_name
--添加外键 alter table tbname add constraint fk_name foreign key (fk_column) references pk_tbname(pk_column) --删除外键 alter table tbname drop constraint fk_name
--添加唯一约束 alter table tbname add constraint uq_colname unique (colname)