Skip to content

Instantly share code, notes, and snippets.

View gourab5139014's full-sized avatar

Gourab Mitra gourab5139014

View GitHub Profile
@gourab5139014
gourab5139014 / showRelationships.sql
Last active March 26, 2024 14:59
SQL Server Script to show all FK relationships in the current database
SELECT
fk.name 'FK Name',
tp.name 'Parent table',
cp.name, cp.column_id,
tr.name 'Referenced table',
cr.name, cr.column_id
FROM
sys.foreign_keys fk
INNER JOIN
sys.tables tp ON fk.parent_object_id = tp.object_id