Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Locate primary key - foreign key relations

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.

Mohit Nayyar

Total article views: 2703 | Views in the last 30 days: 4
Related Articles

Primary-Foreign Key

Primary-Foreign Key


Effectively mapping primary key – foreign key relations

This script maps the primary key - foreign key relations regardless if the column names are the same...


Primary and foreign keys

Can a primary key be a foreign key too?


working with primary key column

working with primary key column


The Ultimate Foreign Key Researcher

Searches for actual and potential foreign key columns for a given primary key reference.


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

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.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones