DECLARE @nocheckSql NVARCHAR(max)--禁用外键约束的sql
SET @nocheckSql =
(SELECT 'alter table dbo.['+b.name+'] nocheck constraint ['+a.name+'];'
from sysobjects a,sysobjects b where a.xtype='f' and a.parent_obj=b.id and b.xtype='u' for xml PATH('')
)
print @nocheckSql
--execute sp_executesql @nocheckSql
DECLARE @checkSql NVARCHAR(max)--启用外键约束的sql
SET @checkSql =
(SELECT 'alter table dbo.['+b.name+'] check constraint ['+a.name+'];'
from sysobjects a,sysobjects b where a.xtype='f' and a.parent_obj=b.id and b.xtype='u' for xml PATH('')
)
print @checkSql
SET @nocheckSql =
(SELECT 'alter table dbo.['+b.name+'] nocheck constraint ['+a.name+'];'
from sysobjects a,sysobjects b where a.xtype='f' and a.parent_obj=b.id and b.xtype='u' for xml PATH('')
)
print @nocheckSql
--execute sp_executesql @nocheckSql
DECLARE @checkSql NVARCHAR(max)--启用外键约束的sql
SET @checkSql =
(SELECT 'alter table dbo.['+b.name+'] check constraint ['+a.name+'];'
from sysobjects a,sysobjects b where a.xtype='f' and a.parent_obj=b.id and b.xtype='u' for xml PATH('')
)
print @checkSql