select  'ALTER TABLE ['  + b.name +  '] NOCHECK CONSTRAINT ' +  a.name +';' as  禁用约束     
from sysobjects a ,sysobjects b
where a.xtype ='f' and a.parent_obj = b.id


--获得启用所有外键约束的语句
select 'ALTER TABLE [' + b.name + '] CHECK CONSTRAINT ' + a.name +';' as 启用约束
from sysobjects a ,sysobjects b
where a.xtype ='f' and a.parent_obj = b.id

USE DWS_QAS
GO

EXEC SP_MSFOREACHTABLE 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

DELETE DWS_QAS.[dbo].[Printer]
DELETE DWS_QAS.[dbo].[PrintLabelTasks]
DELETE DWS_QAS.[dbo].[PrintLabelTasksHistory]
DELETE DWS_QAS.[dbo].[SalesIDocs]
DELETE DWS_QAS.[dbo].[UserDefaultPrinter]
DELETE DWS_QAS.[dbo].[WorkstationPrinter]
DELETE DWS_QAS.[dbo].[Companys]
DELETE DWS_QAS.[dbo].[Plants]
DELETE DWS_QAS.[dbo].[UserPlant]

EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'