Updated on 2026-10-26 GMT+08:00

Disabling All Triggers and Foreign Keys on the Destination End

Disabling All Table-Level Triggers

Run the following SQL statements to disable all marked triggers:

DECLARE @sql NVARCHAR(MAX) = '';
SELECT @sql = @sql + 'DISABLE TRIGGER ' + QUOTENAME(name) + ' ON ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_id)) + '.' + QUOTENAME(OBJECT_NAME(parent_id)) + ';' + CHAR(13)
FROM sys.triggers
WHERE is_ms_shipped = 0 -- Exclude system triggers.
AND parent_class_desc = 'OBJECT_OR_COLUMN'; -- Only table-level triggers are included.
EXEC sp_executesql @sql;

Disabling Database-Level Triggers

Run the following command to disable database-level DDL triggers:
DISABLE TRIGGER ALL ON DATABASE

Disabling All Foreign Keys

  1. Check the original foreign keys.
    Figure 1 Checking the original foreign keys
  2. Run the following SQL statements to disable all foreign keys:
    DECLARE @sql NVARCHAR(MAX) = '';
    SELECT @sql = @sql + 'ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.' + QUOTENAME(OBJECT_NAME(parent_object_id)) + ' NOCHECK CONSTRAINT ' + QUOTENAME(name) + ';' + CHAR(13)
    FROM sys.foreign_keys;
    EXEC sp_executesql @sql;
    Figure 2 Disabling foreign keys
  3. Check the foreign keys again. You can see that the foreign keys are disabled.
    Figure 3 Checking the foreign keys