Help Center/ Data Replication Service/ Best Practices/ Real-Time Synchronization/ From Azure SQL DB to RDS for SQL Server/ Preparing Data for Migration/ Disabling All Triggers and Foreign Keys on the Destination End
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
- Check the original foreign keys. Figure 1 Checking the original foreign keys
- 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
- Check the foreign keys again. You can see that the foreign keys are disabled. Figure 3 Checking the foreign keys
Parent topic: Preparing Data for Migration
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot