<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; 2008 &#8211; Find Relationship of Foreign Key and Primary Key using T-SQL &#8211; Find Tables With Foreign Key Constraint in Database</title>
	<atom:link href="http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:36:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Aravind</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-242998</link>
		<dc:creator><![CDATA[Aravind]]></dc:creator>
		<pubDate>Tue, 24 Jan 2012 12:09:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-242998</guid>
		<description><![CDATA[i want tables like this...

Table1                             
id name country

2  xyz      India
--------------------------
Table2

id aaa bbb ccc
2
2
---------------------------
Table 3

id xx yy zz
2
2]]></description>
		<content:encoded><![CDATA[<p>i want tables like this&#8230;</p>
<p>Table1<br />
id name country</p>
<p>2  xyz      India<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Table2</p>
<p>id aaa bbb ccc<br />
2<br />
2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Table 3</p>
<p>id xx yy zz<br />
2<br />
2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aravind</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-242996</link>
		<dc:creator><![CDATA[Aravind]]></dc:creator>
		<pubDate>Tue, 24 Jan 2012 12:07:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-242996</guid>
		<description><![CDATA[Hi Pinal,
              This is my sample tables...

Table1                             
id name country
1  xyz      US
2  xyz      India
--------------------------
Table2

id aaa bbb ccc
1
2
---------------------------
Table 3

id xx yy zz
1
2]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
              This is my sample tables&#8230;</p>
<p>Table1<br />
id name country<br />
1  xyz      US<br />
2  xyz      India<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Table2</p>
<p>id aaa bbb ccc<br />
1<br />
2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Table 3</p>
<p>id xx yy zz<br />
1<br />
2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aravind</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-242994</link>
		<dc:creator><![CDATA[Aravind]]></dc:creator>
		<pubDate>Tue, 24 Jan 2012 12:03:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-242994</guid>
		<description><![CDATA[Hi Pinal,

I am a beginner in SQLServer.i want to update and delete more then two tables
using merge concepts.so kindly let me send query asap....  
Note:Tables are relate with foreign key,primary key constrains..

Thanks,]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I am a beginner in SQLServer.i want to update and delete more then two tables<br />
using merge concepts.so kindly let me send query asap&#8230;.<br />
Note:Tables are relate with foreign key,primary key constrains..</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: soonerfan1982Jason West</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-241206</link>
		<dc:creator><![CDATA[soonerfan1982Jason West]]></dc:creator>
		<pubDate>Fri, 20 Jan 2012 07:44:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-241206</guid>
		<description><![CDATA[Pinal, I often come across your blog when trying to solve a SQL issue. Thank you so much for all of the work you do to provide such a great resource! It is much appreciated]]></description>
		<content:encoded><![CDATA[<p>Pinal, I often come across your blog when trying to solve a SQL issue. Thank you so much for all of the work you do to provide such a great resource! It is much appreciated</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-240882</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Thu, 19 Jan 2012 17:53:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-240882</guid>
		<description><![CDATA[Great suggestion @jlangdon!]]></description>
		<content:encoded><![CDATA[<p>Great suggestion @jlangdon!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffrey Langdon @jlangdon</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-240869</link>
		<dc:creator><![CDATA[Jeffrey Langdon @jlangdon]]></dc:creator>
		<pubDate>Thu, 19 Jan 2012 17:29:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-240869</guid>
		<description><![CDATA[Thanks Dave. Nice script to have. I just added a where clause so that I can filter by table name. 

WHERE OBJECT_NAME(f.parent_object_id)= &#039;tablename&#039;]]></description>
		<content:encoded><![CDATA[<p>Thanks Dave. Nice script to have. I just added a where clause so that I can filter by table name. </p>
<p>WHERE OBJECT_NAME(f.parent_object_id)= &#8216;tablename&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: .NETDev</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-175505</link>
		<dc:creator><![CDATA[.NETDev]]></dc:creator>
		<pubDate>Thu, 06 Oct 2011 01:36:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-175505</guid>
		<description><![CDATA[Thanks, this was handy]]></description>
		<content:encoded><![CDATA[<p>Thanks, this was handy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stevenb</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-138422</link>
		<dc:creator><![CDATA[stevenb]]></dc:creator>
		<pubDate>Thu, 02 Jun 2011 14:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-138422</guid>
		<description><![CDATA[Dave,

Your knowledge and examples are great.  I get just the answers I&#039;m looking for.

Thank you, thank you, thank you!]]></description>
		<content:encoded><![CDATA[<p>Dave,</p>
<p>Your knowledge and examples are great.  I get just the answers I&#8217;m looking for.</p>
<p>Thank you, thank you, thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-110896</link>
		<dc:creator><![CDATA[Chuck]]></dc:creator>
		<pubDate>Thu, 13 Jan 2011 22:02:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-110896</guid>
		<description><![CDATA[This was great.  I was wondering though..can you provide an example where if a relationship exists...

Drop the relationship/contstraint

What I want to do is create table and its relationships, but if I need to drop the parent table, I want to drop the respective relationships before hand.

Thanks.]]></description>
		<content:encoded><![CDATA[<p>This was great.  I was wondering though..can you provide an example where if a relationship exists&#8230;</p>
<p>Drop the relationship/contstraint</p>
<p>What I want to do is create table and its relationships, but if I need to drop the parent table, I want to drop the respective relationships before hand.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: atusa</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-75945</link>
		<dc:creator><![CDATA[atusa]]></dc:creator>
		<pubDate>Sun, 13 Jun 2010 09:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-75945</guid>
		<description><![CDATA[Thanks a lot. It was a great help for me. 
Regards.]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot. It was a great help for me.<br />
Regards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mehmood</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-68916</link>
		<dc:creator><![CDATA[mehmood]]></dc:creator>
		<pubDate>Tue, 04 May 2010 13:20:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-68916</guid>
		<description><![CDATA[Sorry i sent a wrong query . i am trying this one:

 select ISNULL(c.constraint_name,&#039;&#039;) ConstraintName,
	
	ISNULL(cfk.table_name ,&#039;&#039;) FK_Table_name,
	
	ISNULL(kcu.column_name ,&#039;&#039;) FK_Column_name,

	ISNULL(cpk.table_name ,&#039;&#039;) PK_Table_name,

	ISNULL(pkt.column_name ,&#039;&#039;) PK_COlumn_name		
	
	from information_schema.REFERENTIAL_CONSTRAINTS c 
	
	INNER JOIN information_schema.TABLE_CONSTRAINTS cpk  on c.unique_constraint_name = cpk.constraint_name
	
	INNER JOIN information_schema.TABLE_CONSTRAINTS cfk  on c.constraint_name = cfk.constraint_name
	
	INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE  kcu  ON c.constraint_name  = kcu.constraint_name
	
	INNER JOIN 
	(
		SELECT tci.table_name, kcui.column_name  FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tci 
	        INNER JOIN  INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcui on tci.constraint_name = kcui.constraint_name
	        WHERE tci.CONSTRAINT_TYPE = &#039;PRIMARY KEY&#039;
	
	) PKT   ON PKT.TABLE_NAME = CPK.TABLE_NAME
	    GROUP BY c.constraint_name,cfk.table_name, kcu.column_name, cpk.table_name, pkt.column_name
        HAVING count(pkt.column_name) = 1  and
        cfk.table_name = &#039;bp_bank&#039; 
	ORDER BY 1,2,3,4]]></description>
		<content:encoded><![CDATA[<p>Sorry i sent a wrong query . i am trying this one:</p>
<p> select ISNULL(c.constraint_name,&#8221;) ConstraintName,</p>
<p>	ISNULL(cfk.table_name ,&#8221;) FK_Table_name,</p>
<p>	ISNULL(kcu.column_name ,&#8221;) FK_Column_name,</p>
<p>	ISNULL(cpk.table_name ,&#8221;) PK_Table_name,</p>
<p>	ISNULL(pkt.column_name ,&#8221;) PK_COlumn_name		</p>
<p>	from information_schema.REFERENTIAL_CONSTRAINTS c </p>
<p>	INNER JOIN information_schema.TABLE_CONSTRAINTS cpk  on c.unique_constraint_name = cpk.constraint_name</p>
<p>	INNER JOIN information_schema.TABLE_CONSTRAINTS cfk  on c.constraint_name = cfk.constraint_name</p>
<p>	INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE  kcu  ON c.constraint_name  = kcu.constraint_name</p>
<p>	INNER JOIN<br />
	(<br />
		SELECT tci.table_name, kcui.column_name  FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tci<br />
	        INNER JOIN  INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcui on tci.constraint_name = kcui.constraint_name<br />
	        WHERE tci.CONSTRAINT_TYPE = &#8216;PRIMARY KEY&#8217;</p>
<p>	) PKT   ON PKT.TABLE_NAME = CPK.TABLE_NAME<br />
	    GROUP BY c.constraint_name,cfk.table_name, kcu.column_name, cpk.table_name, pkt.column_name<br />
        HAVING count(pkt.column_name) = 1  and<br />
        cfk.table_name = &#8216;bp_bank&#8217;<br />
	ORDER BY 1,2,3,4</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mehmood</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-68915</link>
		<dc:creator><![CDATA[mehmood]]></dc:creator>
		<pubDate>Tue, 04 May 2010 13:18:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-68915</guid>
		<description><![CDATA[my database version is 2000.]]></description>
		<content:encoded><![CDATA[<p>my database version is 2000.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mehmood</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-68913</link>
		<dc:creator><![CDATA[mehmood]]></dc:creator>
		<pubDate>Tue, 04 May 2010 13:17:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-68913</guid>
		<description><![CDATA[Hi..

i am facing a problem while retreiving foreign keys.
i am passing foreign key table in below your query but i returns some extra columns or you can say some of its column&#039;s data is beign duplicate.
how can i handle this?
thnxk

SELECT f.name AS ForeignKey,
SCHEMA_NAME(f.SCHEMA_ID) SchemaName,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id
ON f.OBJECT_ID = fc.constraint_object_id]]></description>
		<content:encoded><![CDATA[<p>Hi..</p>
<p>i am facing a problem while retreiving foreign keys.<br />
i am passing foreign key table in below your query but i returns some extra columns or you can say some of its column&#8217;s data is beign duplicate.<br />
how can i handle this?<br />
thnxk</p>
<p>SELECT f.name AS ForeignKey,<br />
SCHEMA_NAME(f.SCHEMA_ID) SchemaName,<br />
OBJECT_NAME(f.parent_object_id) AS TableName,<br />
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,<br />
SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName,<br />
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,<br />
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName<br />
FROM sys.foreign_keys AS f<br />
INNER JOIN sys.foreign_key_columns AS fc<br />
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id<br />
ON f.OBJECT_ID = fc.constraint_object_id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-61701</link>
		<dc:creator><![CDATA[Pinal Dave]]></dc:creator>
		<pubDate>Wed, 24 Feb 2010 13:59:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-61701</guid>
		<description><![CDATA[Hello Mac,

If I remove the alias then the query would like following:

FROM sys.foreign_keys 
INNER JOIN sys.foreign_key_columns
INNER JOIN sys.objects 
ON sys.objects.OBJECT_ID = sys.foreign_key_columns.referenced_object_id 
ON sys.foreign_keys.OBJECT_ID = sys.foreign_key_columns.constraint_object_id

Notice that both ON clause are on different tables.

Regards,
Pinal Dave]]></description>
		<content:encoded><![CDATA[<p>Hello Mac,</p>
<p>If I remove the alias then the query would like following:</p>
<p>FROM sys.foreign_keys<br />
INNER JOIN sys.foreign_key_columns<br />
INNER JOIN sys.objects<br />
ON sys.objects.OBJECT_ID = sys.foreign_key_columns.referenced_object_id<br />
ON sys.foreign_keys.OBJECT_ID = sys.foreign_key_columns.constraint_object_id</p>
<p>Notice that both ON clause are on different tables.</p>
<p>Regards,<br />
Pinal Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mac Addict</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-61666</link>
		<dc:creator><![CDATA[Mac Addict]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 23:09:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-61666</guid>
		<description><![CDATA[Pinal - You got me. (From your script)How is follow script able to work? An inner join without any clause and another with two conditions not seperated by any operator. Please explain.

...
INNER JOIN 
	sys.foreign_key_columns AS fc
INNER JOIN 
	sys.objects AS o 
	ON o.OBJECT_ID = fc.referenced_object_id
	ON f.OBJECT_ID = fc.constraint_object_id]]></description>
		<content:encoded><![CDATA[<p>Pinal &#8211; You got me. (From your script)How is follow script able to work? An inner join without any clause and another with two conditions not seperated by any operator. Please explain.</p>
<p>&#8230;<br />
INNER JOIN<br />
	sys.foreign_key_columns AS fc<br />
INNER JOIN<br />
	sys.objects AS o<br />
	ON o.OBJECT_ID = fc.referenced_object_id<br />
	ON f.OBJECT_ID = fc.constraint_object_id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derrick</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-58682</link>
		<dc:creator><![CDATA[Derrick]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 23:06:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-58682</guid>
		<description><![CDATA[Easily, the article is in reality the sweetest on this laudable topic. I agree with your conclusions and will eagerly look forward to your approaching updates. Just saying thanks will not just be enough, for the tremendous lucidity in your writing. I will immediately grab your rss feed to stay privy of any updates. Good work and much success in your business efforts!]]></description>
		<content:encoded><![CDATA[<p>Easily, the article is in reality the sweetest on this laudable topic. I agree with your conclusions and will eagerly look forward to your approaching updates. Just saying thanks will not just be enough, for the tremendous lucidity in your writing. I will immediately grab your rss feed to stay privy of any updates. Good work and much success in your business efforts!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry Hung</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-47538</link>
		<dc:creator><![CDATA[Jerry Hung]]></dc:creator>
		<pubDate>Thu, 26 Feb 2009 19:55:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-47538</guid>
		<description><![CDATA[Always fun to turn a script for 1 DB to ALL DB&#039;s


sp_MSForEachDB &#039;
if &#039;&#039;?&#039;&#039; NOT IN (&#039;&#039;tempdb&#039;&#039;,&#039;&#039;master&#039;&#039;,&#039;&#039;model&#039;&#039;,&#039;&#039;msdb&#039;&#039;) USE ?
SELECT  
	DBName = DB_NAME()
	,f.name AS ForeignKey
	,SCHEMA_NAME(f.SCHEMA_ID) SchemaName
	,OBJECT_NAME(f.parent_object_id) AS TableName
	,COL_NAME(fc.parent_object_id, fc.parent_column_id) AS ColumnName
	,SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName
	,OBJECT_NAME(f.referenced_object_id) AS ReferenceTableName
	,COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ReferenceColumnName
FROM    sys.foreign_keys AS f
        INNER JOIN sys.foreign_key_columns AS fc
        INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id ON f.OBJECT_ID = fc.constraint_object_id
&#039;]]></description>
		<content:encoded><![CDATA[<p>Always fun to turn a script for 1 DB to ALL DB&#8217;s</p>
<p>sp_MSForEachDB &#8216;<br />
if &#8221;?&#8221; NOT IN (&#8221;tempdb&#8221;,&#8221;master&#8221;,&#8221;model&#8221;,&#8221;msdb&#8221;) USE ?<br />
SELECT<br />
	DBName = DB_NAME()<br />
	,f.name AS ForeignKey<br />
	,SCHEMA_NAME(f.SCHEMA_ID) SchemaName<br />
	,OBJECT_NAME(f.parent_object_id) AS TableName<br />
	,COL_NAME(fc.parent_object_id, fc.parent_column_id) AS ColumnName<br />
	,SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName<br />
	,OBJECT_NAME(f.referenced_object_id) AS ReferenceTableName<br />
	,COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ReferenceColumnName<br />
FROM    sys.foreign_keys AS f<br />
        INNER JOIN sys.foreign_key_columns AS fc<br />
        INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id ON f.OBJECT_ID = fc.constraint_object_id<br />
&#8216;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: irfan</title>
		<link>http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/#comment-47519</link>
		<dc:creator><![CDATA[irfan]]></dc:creator>
		<pubDate>Thu, 26 Feb 2009 13:42:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2799#comment-47519</guid>
		<description><![CDATA[nice script!]]></description>
		<content:encoded><![CDATA[<p>nice script!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

