This article is half-done without your Comment! *** Please share your thoughts via Comment ***
I already shared an article on how to enable or disable the foreign keys in the SQL Server.
Enable and Disable Foreign key and Check constraint in SQL Server
Why we require this? To make faster data migration by disabling the foreign key constraint.
For example, Now foreign key constraint disabled, and you load/migrate the data. Next, you enable the foreign key constraint with NOCHECK option.
That means if your key data do not reference of your primary key then also it allows the foreign key constraint that is called untrusted or invalid foreign key constraint because data is invalid.
You must find out untrusted or invalid foreign keys from your SQL Server so that you can take appropriate action on invalid referenced data.
Use below script to find untrusted or invalid foregin keys:
1 2 3 4 5 6 7 8 9 |
SELECT '[' + s.name + '].[' + o.name + '].[' + f.name + ']' AS ForeignKeyName FROM sys.foreign_keys f INNER JOIN sys.objects o ON f.parent_object_id = o.object_id INNER JOIN sys.schemas s ON o.schema_id = s.schema_id WHERE f.is_not_trusted = 1 AND f.is_not_for_replication = 0 AND f.is_disabled = 0 |
Leave a Reply