This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am going to share one of the important script for SQL Serve DBA to find a list of tables which have disable foreign keys.
In any RDBMS system, the rule of data integrity is mandatory because it ensures the quality of data.
In our organization, database developers sometime disable the foreign key constraint because they required to insert test data or required to import non-related data.
After this testing, there are 90% chance of forgetting to enable foreign key constraint again to maintain further data integrity.
Using below script,the DBA can find a list of tables which have disable foreign key constraints.
1 2 3 4 5 6 7 8 9 10 11 |
SELECT [s].[name] + '.' + [t].[name] AS TableName FROM [sys].[tables] AS t INNER JOIN [sys].[schemas] AS s ON [t].[schema_id] = [s].[schema_id] WHERE EXISTS ( SELECT 1 FROM [sys].[foreign_keys] AS fk WHERE [fk].[parent_object_id] = [t].[object_id] AND [fk].[is_disabled] = 1 ); |
Leave a Reply