Member of the LearnItFirst.com Video Training Network | LearnSqlServer.com | SQL SSIS Training | SQL Programming Tutorials |
LearnSqlServer.com Forums LearnSqlServer.com
Welcome Guest Search | New Posts | Members | Log In | Register

List all foreign keys for all tables Options
Scott Whigham
Posted: Monday, August 28, 2006 11:24:45 AM


Rank: Super Mod

Joined: 3/20/2006
Posts: 345
Points: 748
Location: Dallas, TX
Code:
/*
    Author: Scott Whigham from http://www.LearnSqlServer.com/

    Description: This script lists all foreign keys for all tables
   
    Versions: SQL Server 2005, 2000, 7.0
   
    Creation Date: August 28, 2006

    For more scripts like this one, visit http://forums.learnsqlserver.com/codesamples.aspx
*/
SELECT Child.TABLE_NAME AS [Child Table]
    , Parent.TABLE_NAME AS [Parent Table]
    , RC.CONSTRAINT_NAME AS [FK Name]
    , RC.UPDATE_RULE [Cascade Updates]
    , RC.DELETE_RULE AS [Cascade Deletes]
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS Child
   ON RC.CONSTRAINT_NAME = Child.CONSTRAINT_NAME
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS Parent
   ON RC.UNIQUE_CONSTRAINT_NAME = Parent.CONSTRAINT_NAME
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
     
Don't Forget!
LearnItFirst.com
Don't Forget!
LearnExchange.com
 
Home | About Us | Support | Contact Us | Privacy | Site Map | Blogs Blogs Refer a Friend and Get a Free Subscription!
© Copyright 2004-2007 LearnItFirst.com LLC. All rights reserved. All trademarks remain the property of their respective owners.
This site is not affiliated in any way with the Microsoft Corporation.