Temporarily disable all foreign key constraints
问题 I am running an SSIS package which will replace data for a few tables from FlatFiles to existing tables in a database. My package will truncate the tables and then insert the new data. When I run my SSIS package, I get an exception because of the foreign keys. Can I disable the constraints, run my import, then re-enable them? 回答1: To disable foreign key constraints: DECLARE @sql NVARCHAR(MAX) = N''; ;WITH x AS ( SELECT DISTINCT obj = QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.' +