Nearly identical to Query a Table's Foreign Key relationships, but for SQL Server 2000
For a given table \'foo\', I need a query to generate a set of ta
Parents and children
/* this will find out all of the foreign key references for a table*/
DECLARE @tableName varchar(128)
SET @tableName = 'tCounter'
SELECT
pt.[name] AS 'parentTable',
ct.[name] AS 'childTable',
fk.[name] AS 'fkName',
*
FROM sys.foreign_keys fk
INNER JOIN sys.tables pt
ON pt.object_ID = fk.parent_object_id
INNER JOIN sys.tables ct
ON ct.object_ID = fk.referenced_object_id
WHERE pt.name = @tableName
OR ct.name = @tableName
ORDER BY pt.name, ct.name