<?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; 2005 &#8211; Find Tables With Foreign Key Constraint in Database</title>
	<atom:link href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Zia Rizvi</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-52782</link>
		<dc:creator>Zia Rizvi</dc:creator>
		<pubDate>Fri, 05 Jun 2009 21:42:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-52782</guid>
		<description>Excellent query. I was thrown into the project to work on somebody else&#039;s database design. I was supposed to right a data export procedure and this script CAME SO HANDY so find all the keys and the to right the stored procedure that return the data i want. Iit would have been impossible to find the relationships and then develop the procedure. AWESOME AWESOME!!!!!!!!!!!!!!</description>
		<content:encoded><![CDATA[<p>Excellent query. I was thrown into the project to work on somebody else&#8217;s database design. I was supposed to right a data export procedure and this script CAME SO HANDY so find all the keys and the to right the stored procedure that return the data i want. Iit would have been impossible to find the relationships and then develop the procedure. AWESOME AWESOME!!!!!!!!!!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-51043</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 16 Apr 2009 15:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-51043</guid>
		<description>Dude that rocks! You saved me a lot of frustation. Thank you. Thank you.</description>
		<content:encoded><![CDATA[<p>Dude that rocks! You saved me a lot of frustation. Thank you. Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - 2005 Find Table without Clustered Index - Find Table with no Primary Key Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-49762</link>
		<dc:creator>SQL SERVER - 2005 Find Table without Clustered Index - Find Table with no Primary Key Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Mon, 23 Mar 2009 10:59:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-49762</guid>
		<description>[...] Related Post: SQL SERVER - 2005 - Find Tables With Primary Key Constraint in Database SQL SERVER - 2005 - Find Tables With Foreign Key Constraint in Database  [...]</description>
		<content:encoded><![CDATA[<p>[...] Related Post: SQL SERVER &#8211; 2005 &#8211; Find Tables With Primary Key Constraint in Database SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-48238</link>
		<dc:creator>Ravi</dc:creator>
		<pubDate>Fri, 06 Mar 2009 09:35:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-48238</guid>
		<description>It&#039;s really very good script.it is very unique and useful script.keep it up pinal.You are doing very well job.</description>
		<content:encoded><![CDATA[<p>It&#8217;s really very good script.it is very unique and useful script.keep it up pinal.You are doing very well job.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - 2008 - Find Relationship of Foreign Key and Primary Key using T-SQL - Find Tables With Foreign Key Constraint in Database Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-47513</link>
		<dc:creator>SQL SERVER - 2008 - Find Relationship of Foreign Key and Primary Key using T-SQL - Find Tables With Foreign Key Constraint in Database Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Thu, 26 Feb 2009 12:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-47513</guid>
		<description>[...] Key and Foreign Key relationship using T-SQL, I came across my own blog article written earlier SQL SERVER - 2005 - Find Tables With Foreign Key Constraint in Database. It is really handy script and not found written on line anywhere. This is one really unique script [...]</description>
		<content:encoded><![CDATA[<p>[...] Key and Foreign Key relationship using T-SQL, I came across my own blog article written earlier SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database. It is really handy script and not found written on line anywhere. This is one really unique script [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-47245</link>
		<dc:creator>SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Tue, 24 Feb 2009 12:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-47245</guid>
		<description>[...] SQL SERVER - 2005 - Find Tables With Foreign Key Constraint in Database [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sharmila</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-45573</link>
		<dc:creator>Sharmila</dc:creator>
		<pubDate>Tue, 13 Jan 2009 12:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-45573</guid>
		<description>Hi, ur articles always found very useful. thanks.  I hv one query.. i hv constraint on my master table, but there are excess data in my master, which not yet used in sub tables. I want to delete master data which is not used in subtable. Is it possible to delete thru sql? i m using sql 2005.

thanks</description>
		<content:encoded><![CDATA[<p>Hi, ur articles always found very useful. thanks.  I hv one query.. i hv constraint on my master table, but there are excess data in my master, which not yet used in sub tables. I want to delete master data which is not used in subtable. Is it possible to delete thru sql? i m using sql 2005.</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Vandenpanhuyzen</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-42684</link>
		<dc:creator>Jan Vandenpanhuyzen</dc:creator>
		<pubDate>Thu, 11 Sep 2008 11:27:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-42684</guid>
		<description>George,

I&#039;ve a script that does the same but is a little less complicated I think:

SELECT TABLE_NAME, TABLE_SCHEMA, COLUMN_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
INNER JOIN sys.foreign_keys f
ON CCU.TABLE_NAME = object_name(parent_object_id) and CONSTRAINT_NAME = f.name
WHERE f.type = &#039;F&#039;
AND NOT EXISTS (
SELECT OBJECT_NAME(i.object_id) AS tablename,
i.name AS indexname, 
a.name AS columnname 
FROM sys.indexes i 
INNER JOIN sys.index_columns c 
ON i.object_id = c.object_id AND i.index_id = c.index_id
INNER JOIN sys.all_columns a
ON a.object_id = c.object_id AND a.column_id = c.column_id
WHERE CCU.TABLE_NAME = OBJECT_NAME(i.object_id)
AND CCU.COLUMN_NAME = a.name
)

ORDER BY CCU.TABLE_SCHEMA, CCU.TABLE_NAME, CCU.COLUMN_NAME</description>
		<content:encoded><![CDATA[<p>George,</p>
<p>I&#8217;ve a script that does the same but is a little less complicated I think:</p>
<p>SELECT TABLE_NAME, TABLE_SCHEMA, COLUMN_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU<br />
INNER JOIN sys.foreign_keys f<br />
ON CCU.TABLE_NAME = object_name(parent_object_id) and CONSTRAINT_NAME = f.name<br />
WHERE f.type = &#8216;F&#8217;<br />
AND NOT EXISTS (<br />
SELECT OBJECT_NAME(i.object_id) AS tablename,<br />
i.name AS indexname,<br />
a.name AS columnname<br />
FROM sys.indexes i<br />
INNER JOIN sys.index_columns c<br />
ON i.object_id = c.object_id AND i.index_id = c.index_id<br />
INNER JOIN sys.all_columns a<br />
ON a.object_id = c.object_id AND a.column_id = c.column_id<br />
WHERE CCU.TABLE_NAME = OBJECT_NAME(i.object_id)<br />
AND CCU.COLUMN_NAME = a.name<br />
)</p>
<p>ORDER BY CCU.TABLE_SCHEMA, CCU.TABLE_NAME, CCU.COLUMN_NAME</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: venkat</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-39355</link>
		<dc:creator>venkat</dc:creator>
		<pubDate>Thu, 19 Jun 2008 10:49:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-39355</guid>
		<description>simply superb! gr8 work!</description>
		<content:encoded><![CDATA[<p>simply superb! gr8 work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - 2005 - Find Tables With Foreign Key Constraint in Database - Part 2 Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-38285</link>
		<dc:creator>SQL SERVER - 2005 - Find Tables With Foreign Key Constraint in Database - Part 2 Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Sat, 17 May 2008 07:45:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-38285</guid>
		<description>[...] Joffery has provided nice script which is modification to previous article of SQL SERVER - 2005 - Find Tables With Foreign Key Constraint in Database. [...]</description>
		<content:encoded><![CDATA[<p>[...] Joffery has provided nice script which is modification to previous article of SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joffrey</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-38191</link>
		<dc:creator>joffrey</dc:creator>
		<pubDate>Fri, 16 May 2008 08:47:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-38191</guid>
		<description>Hi Pinal

Very interesting article and of great help.
I made a little addition to your code. As I wanted also to know what the FKs are doing in the Table (referential integrity on update and on delete) I added two columns to your superb query. And a little bit of ordering :)
Maybe it helps other readers.

SELECT f.name AS ForeignKey,
   OBJECT_NAME(f.parent_object_id) AS TableName,
   COL_NAME(fc.parent_object_id, 
   fc.parent_column_id) AS ColumnName,
   OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
   COL_NAME(fc.referenced_object_id, 
   fc.referenced_column_id) AS ReferenceColumnName,
   f.update_referential_action_desc AS UpdateAction,
   f.delete_referential_action_desc AS DeleteAction
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
   ON f.OBJECT_ID = fc.constraint_object_id
ORDER BY TableName ASC, ColumnName ASC</description>
		<content:encoded><![CDATA[<p>Hi Pinal</p>
<p>Very interesting article and of great help.<br />
I made a little addition to your code. As I wanted also to know what the FKs are doing in the Table (referential integrity on update and on delete) I added two columns to your superb query. And a little bit of ordering :)<br />
Maybe it helps other readers.</p>
<p>SELECT f.name AS ForeignKey,<br />
   OBJECT_NAME(f.parent_object_id) AS TableName,<br />
   COL_NAME(fc.parent_object_id,<br />
   fc.parent_column_id) AS ColumnName,<br />
   OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,<br />
   COL_NAME(fc.referenced_object_id,<br />
   fc.referenced_column_id) AS ReferenceColumnName,<br />
   f.update_referential_action_desc AS UpdateAction,<br />
   f.delete_referential_action_desc AS DeleteAction<br />
FROM sys.foreign_keys AS f<br />
INNER JOIN sys.foreign_key_columns AS fc<br />
   ON f.OBJECT_ID = fc.constraint_object_id<br />
ORDER BY TableName ASC, ColumnName ASC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TOM</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-38021</link>
		<dc:creator>TOM</dc:creator>
		<pubDate>Wed, 14 May 2008 12:12:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-38021</guid>
		<description>Hi Pinal,

Your articles are always great source of information. Can u provide code i mean query to add FK on  new table

Thanks
Tom</description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Your articles are always great source of information. Can u provide code i mean query to add FK on  new table</p>
<p>Thanks<br />
Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sanjoy Banerjee</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-36849</link>
		<dc:creator>sanjoy Banerjee</dc:creator>
		<pubDate>Mon, 05 May 2008 14:01:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-36849</guid>
		<description>i want to know the Foreign key name between two tables.</description>
		<content:encoded><![CDATA[<p>i want to know the Foreign key name between two tables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: M Azim</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-35672</link>
		<dc:creator>M Azim</dc:creator>
		<pubDate>Sat, 26 Apr 2008 11:31:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-35672</guid>
		<description>Hi Pinal,

Your articles are always great source of information.   

Kind Regards,

Azim</description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Your articles are always great source of information.   </p>
<p>Kind Regards,</p>
<p>Azim</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George Kopf</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-34054</link>
		<dc:creator>George Kopf</dc:creator>
		<pubDate>Fri, 29 Feb 2008 01:29:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-34054</guid>
		<description>I have written a script which I believe will list all the Foreign Key constraints that are missing supporting indexes.  But since I&#039;m very inexperienced with SQL Server I was hoping I could throw this over the fence and let the big dogs chew on it.

Thanks in advance for any and all criticisim.

George


select C.Table_Name,
       C.Constraint_Name,
       C.Constraint_Columns
  from
       (select object_name(i.object_id) table_name,
               i.name index_name, 
               max(case index_column_id when 1 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 2 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 3 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 4 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 5 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 6 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 7 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 8 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 9 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end)+
               max(case index_column_id when 10 then col_name(ic.object_id,ic.column_id) else &#039;&#039; end) index_columns
          from sys.index_columns ic,
               sys.indexes i
         WHERE ic.index_id = i.index_id
           AND ic.object_id = i.object_id
           AND OBJECTPROPERTY(i.OBJECT_ID,&#039;IsUserTable&#039;) = 1 
           AND i.index_id != 1
        GROUP BY i.object_id, i.name) as I RIGHT OUTER JOIN
       (select kcu.table_name,
               kcu.constraint_name,
               max(case kcu.ordinal_position when 1 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 2 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 3 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 4 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 5 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 6 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 7 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 8 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 9 then kcu.column_name else &#039;&#039; end)+
               max(case kcu.ordinal_position when 10 then kcu.column_name else &#039;&#039; end) constraint_columns
          from information_schema.key_column_usage kcu,
               information_schema.referential_constraints rc
         where rc.constraint_name = kcu.constraint_name
         group by kcu.table_name, kcu.constraint_name) as C
on C.Table_Name = I.Table_Name
and I.Index_Columns like C.Constraint_Columns + &#039;%&#039;
where I.Table_Name is null</description>
		<content:encoded><![CDATA[<p>I have written a script which I believe will list all the Foreign Key constraints that are missing supporting indexes.  But since I&#8217;m very inexperienced with SQL Server I was hoping I could throw this over the fence and let the big dogs chew on it.</p>
<p>Thanks in advance for any and all criticisim.</p>
<p>George</p>
<p>select C.Table_Name,<br />
       C.Constraint_Name,<br />
       C.Constraint_Columns<br />
  from<br />
       (select object_name(i.object_id) table_name,<br />
               i.name index_name,<br />
               max(case index_column_id when 1 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 2 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 3 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 4 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 5 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 6 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 7 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 8 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 9 then col_name(ic.object_id,ic.column_id) else &#8221; end)+<br />
               max(case index_column_id when 10 then col_name(ic.object_id,ic.column_id) else &#8221; end) index_columns<br />
          from sys.index_columns ic,<br />
               sys.indexes i<br />
         WHERE ic.index_id = i.index_id<br />
           AND ic.object_id = i.object_id<br />
           AND OBJECTPROPERTY(i.OBJECT_ID,&#8217;IsUserTable&#8217;) = 1<br />
           AND i.index_id != 1<br />
        GROUP BY i.object_id, i.name) as I RIGHT OUTER JOIN<br />
       (select kcu.table_name,<br />
               kcu.constraint_name,<br />
               max(case kcu.ordinal_position when 1 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 2 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 3 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 4 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 5 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 6 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 7 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 8 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 9 then kcu.column_name else &#8221; end)+<br />
               max(case kcu.ordinal_position when 10 then kcu.column_name else &#8221; end) constraint_columns<br />
          from information_schema.key_column_usage kcu,<br />
               information_schema.referential_constraints rc<br />
         where rc.constraint_name = kcu.constraint_name<br />
         group by kcu.table_name, kcu.constraint_name) as C<br />
on C.Table_Name = I.Table_Name<br />
and I.Index_Columns like C.Constraint_Columns + &#8216;%&#8217;<br />
where I.Table_Name is null</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roland</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-17483</link>
		<dc:creator>roland</dc:creator>
		<pubDate>Sun, 04 Nov 2007 23:54:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-17483</guid>
		<description>@jigar:

SELECT     sfk.fkeyid, sof.name AS fTableName, sor.name AS rTableName, scf.name AS fColName, scr.name AS rColName
FROM         dbo.sysforeignkeys sfk INNER JOIN
                      dbo.sysobjects sof ON sfk.fkeyid = sof.id INNER JOIN
                      dbo.sysobjects sor ON sfk.rkeyid = sor.id INNER JOIN
                      dbo.syscolumns scf ON sfk.fkey = scf.colid AND sof.id = scf.id INNER JOIN
                      dbo.syscolumns scr ON sfk.rkey = scr.colid AND sor.id = scr.id</description>
		<content:encoded><![CDATA[<p>@jigar:</p>
<p>SELECT     sfk.fkeyid, sof.name AS fTableName, sor.name AS rTableName, scf.name AS fColName, scr.name AS rColName<br />
FROM         dbo.sysforeignkeys sfk INNER JOIN<br />
                      dbo.sysobjects sof ON sfk.fkeyid = sof.id INNER JOIN<br />
                      dbo.sysobjects sor ON sfk.rkeyid = sor.id INNER JOIN<br />
                      dbo.syscolumns scf ON sfk.fkey = scf.colid AND sof.id = scf.id INNER JOIN<br />
                      dbo.syscolumns scr ON sfk.rkey = scr.colid AND sor.id = scr.id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prasad</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-15330</link>
		<dc:creator>Prasad</dc:creator>
		<pubDate>Sun, 14 Oct 2007 21:52:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-15330</guid>
		<description>Hi Pinal,
I have a requirement where in for a given View, I need to find out all the tables that are used in the view and I also need to find out how each table in the view is linked.

For example, if I create a simple view like

SELECT * 
FROM TableA
INNER JOIN TableB ON TableA.ID = TableB.FKID
INNER JOIN TableC ON TableA.ID = TableC.FKID


I need to find out all the Tables involved in the view i.e. TableA, TableB and TableC. I also need to find out how TableA and TableB, TableA and TableC are linked (i mean the join Condition).

Could you please point me to resources that can help me find the answer to this.
Thanks
Prasad</description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
I have a requirement where in for a given View, I need to find out all the tables that are used in the view and I also need to find out how each table in the view is linked.</p>
<p>For example, if I create a simple view like</p>
<p>SELECT *<br />
FROM TableA<br />
INNER JOIN TableB ON TableA.ID = TableB.FKID<br />
INNER JOIN TableC ON TableA.ID = TableC.FKID</p>
<p>I need to find out all the Tables involved in the view i.e. TableA, TableB and TableC. I also need to find out how TableA and TableB, TableA and TableC are linked (i mean the join Condition).</p>
<p>Could you please point me to resources that can help me find the answer to this.<br />
Thanks<br />
Prasad</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-14651</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Wed, 03 Oct 2007 01:00:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-14651</guid>
		<description>Hi 

@Milli,
This can be only done manually analyzing the data.

@Jigar,
I only support SQL Server 2005.

Regards,
Pinal Dave ( http://www.SQLAuthority.com )</description>
		<content:encoded><![CDATA[<p>Hi </p>
<p>@Milli,<br />
This can be only done manually analyzing the data.</p>
<p>@Jigar,<br />
I only support SQL Server 2005.</p>
<p>Regards,<br />
Pinal Dave ( <a href="http://www.SQLAuthority.com" rel="nofollow">http://www.SQLAuthority.com</a> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jigar</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-14535</link>
		<dc:creator>Jigar</dc:creator>
		<pubDate>Mon, 01 Oct 2007 06:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-14535</guid>
		<description>hello,

I like have script that lists out all the fk contsraints in sql server 200.

Thanks In ADV,

Jack</description>
		<content:encoded><![CDATA[<p>hello,</p>
<p>I like have script that lists out all the fk contsraints in sql server 200.</p>
<p>Thanks In ADV,</p>
<p>Jack</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milli</title>
		<link>http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-14420</link>
		<dc:creator>Milli</dc:creator>
		<pubDate>Fri, 28 Sep 2007 17:17:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/#comment-14420</guid>
		<description>How to write a SQL script to find those tables in which foreign key constraints are missing.</description>
		<content:encoded><![CDATA[<p>How to write a SQL script to find those tables in which foreign key constraints are missing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
