alter table PUB_STRU NOCHECK constraint all;
alter table PUB_STRU CHECK constraint all;
select 'ALTER TABLE ' + b.name + ' NOCHECK CONSTRAINT ' + a.name +';' from sysobjects a ,sysobjects b where a.xtype ='f' and a.parent_obj = b.id and b.name='表名';
select 'ALTER TABLE ' + b.name + ' CHECK CONSTRAINT ' + a.name +';' from sysobjects a ,sysobjects b where a.xtype ='f' and a.parent_obj = b.id and b.name='表名';
ALTER TABLE PUB_STRU NOCHECK CONSTRAINT PUBSTRU_FK1;
ALTER TABLE PUB_STRU NOCHECK CONSTRAINT PUBSTRU_FK2;
ALTER TABLE PUB_STRU CHECK CONSTRAINT PUBSTRU_FK1;
ALTER TABLE PUB_STRU CHECK CONSTRAINT PUBSTRU_FK2;
select name , is_disabled from sys.foreign_keys order by name;
例子:
alter table AdItem drop constraint AdOrder_AdItem_FK1
alter table AdItem
add constraint AdOrder_AdItem_FK1 foreign key (AI_nOrderNo) references AdOrder(AO_nOrderNo)
alter table Student nocheck constraint FK__Student__SchoolN__4222D4EF
alter table Student check constraint FK__Student__SchoolN__4222D4EF
alter table Student nocheck constraint all
alter table Student check constraint all
EXEC sp_MSforeachtable @command1='alter table ? NOCHECK constraint all;
EXEC sp_MSforeachtable @command1='alter table ? CHECK constraint all;
原文