SELECT TableRelation
FROM cte
Order by TableRelation
SELECT DISTINCT DependentTable
FROM cte
thava,
2021-04-14 (first published: 2013-09-04)
SELECT TableRelation
FROM cte
Order by TableRelation
SELECT DISTINCT DependentTable
FROM cte
DECLARE @TableName AS VARCHAR(250)='<Table Name>' ;WITH cte AS ( SELECT cast(OBJECT_NAME (fkc.parent_object_id) as VARCHAR(MAX)) AS TableRelation, OBJECT_NAME(fkc.parent_object_id) AS DependentTable, fkc.parent_object_id AS childID, 1 AS ReLevel FROM sys.foreign_key_columns fkc WHERE fkc.referenced_object_id = OBJECT_ID (@TableName) UNION ALL SELECT cast(c.TableRelation +'-->'+ OBJECT_NAME (fkc.parent_object_id) AS VARCHAR(MAX)) AS TableRelation, OBJECT_NAME(fkc.parent_object_id) AS DependentTable, fkc.parent_object_id AS childID, c.ReLevel + 1 FROM sys.foreign_key_columns fkc INNER JOIN cte c ON fkc.referenced_object_id = c.Childid AND fkc.parent_object_id<>c.childid ) SELECT TableRelation,DependentTable FROM cte
Learn how trusted foreign keys (FK) can help or hurt performance.
2018-08-24 (first published: 2016-03-08)
6,170 reads
Understand what FK's do and how they use indexes. Then use my script to see if they're using good indexes.
2018-06-29 (first published: 2016-02-10)
5,348 reads
If you can understand the data model then you can understand the intent of the application developers.
2018-07-06 (first published: 2016-01-26)
4,816 reads
Foreign Keys are one of the fundamental characteristics of relational databases and enforce the referential integrity. Is it a good idea to index a FK relationship? When can it help?
2016-09-16 (first published: 2015-06-29)
14,675 reads
Aaron Bertrand supplies a script which generates two separate sets of commands: one to drop all foreign key constraints, and one to create them again. These scripts are stored in a table so that, if you drop the constraints and then disaster of some kind strikes during the create, you still have everything handy and can troubleshoot if needed.
2014-10-17
8,457 reads