Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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)

Find Foreign Keys

By Jack Corbett,

This script is fairly self-explanatory. It uses the INFORMATION_SCHEMA views to return all foreign keys within a database including the Parent or Primary Key Table and Column(s) as well as the Child Table and Column(s). This could be adapted to work for any database by creating a stored procedure that accepts an @DbName parameter and adds it to the Views referenced in the From clause to create 3-part naming.

Total article views: 1462 | Views in the last 30 days: 9
 
Tags
foreign keys (fk)    
metadata    
 
Contribute