EXEC sp_MSforeachtable @command1="ALTER TABLE ? NOCHECK CONSTRAINT ALL"
GO
You may also want to do this:
EXEC sp_MSforeachtable @command1="ALTER TABLE ? DISABLE TRIGGER ALL"
GO
To enable them afterwards
EXEC sp_MSforeachtable @command1="ALTER TABLE ? ENABLE TRIGGER ALL"
GO
-- SQL enable all constraints - enable all constraints sql server
-- sp_MSforeachtable is an undocumented system stored procedure
EXEC sp_MSforeachtable @command1="ALTER TABLE ? CHECK CONSTRAINT ALL"
GO
Edit:
If disabling the constraints is not enough, you will have to drop the constraints.
If you're dropping and recreating the tables, you will have to recreate the foreign key constrains afterwards.
If you just need to drop the constrains, you might find this useful:
SQL DROP TABLE foreign key constraint
If you need to write a script to drop and create the constraints, you might find my post here more useful:
SQL Server: Howto get foreign key reference from information_schema?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…