首页 > 代码库 > SqlServer禁用启用触发器、外键约束

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)