Thank this author by sharing:
By Mohit Nayyar,
Recently one of my friend was doing some investigation in a new/unknown database and had really hard time locating the primary key – foreign key relations.
Like it’s really tough to locate these relations when not enforced at database level in terms of primary key and foreign key constraints. But generally all database developers keep the same column names in a database solution and my script is also based on this assumption.
This script will simply search the given column name in all the tables and will also show the relationship (Primary Key / Foreign key) of this column with columns in other tables.
This script maps the primary key - foreign key relations regardless if the column names are the same...
Can a primary key be a foreign key too?
working with primary key column
Searches for actual and potential foreign key columns for a given primary key reference.
As a member of SQLServerCentral, you get free access to loads of fresh content: thousands
of articles and SQL scripts, a library of free eBooks, a weekly database news roundup,
a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals
that makes it such a success.