<?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/"
		>
<channel>
	<title>Comments on: Microsoft SQL Server: How to Find the Foreign Keys in a Database</title>
	<atom:link href="http://www.tech-recipes.com/rx/3194/microsoft-sql-server-how-to-find-the-foreign-keys-in-a-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tech-recipes.com/rx/3194/microsoft-sql-server-how-to-find-the-foreign-keys-in-a-database/</link>
	<description>Computer and technology tutorials and guides</description>
	<lastBuildDate>Fri, 10 Feb 2012 12:22:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Heiner</title>
		<link>http://www.tech-recipes.com/rx/3194/microsoft-sql-server-how-to-find-the-foreign-keys-in-a-database/comment-page-1/#comment-25988</link>
		<dc:creator>Heiner</dc:creator>
		<pubDate>Mon, 15 Dec 2008 15:19:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.tech-recipes.com/?p=3194#comment-25988</guid>
		<description>Hi!

Your sql seems to have problems with foreign keys consisting of several columns. I get for example:

IE_FK_ADDRESS_USER  IE_ADDRESS  INST_ID         IE_USER  HOLDER_ID
IE_FK_ADDRESS_USER  IE_ADDRESS  INST_ID         IE_USER  INST_ID
IE_FK_ADDRESS_USER  IE_ADDRESS  USER_HOLDER_ID  IE_USER  HOLDER_ID
IE_FK_ADDRESS_USER  IE_ADDRESS  USER_HOLDER_ID  IE_USER  INST_ID

but just the second and third row are okay. I am far from being an sql expert, but the following select returns the correct result for my database:

SELECT 
ConstraintName = a.CONSTRAINT_NAME, 
FromTable = c.TABLE_NAME, 
FromColumn = c.COLUMN_NAME, 
ToTable = d.TABLE_NAME, 
ToColumn = d.COLUMN_NAME 
FROM 
INFORMATION_SCHEMA.TABLE_CONSTRAINTS a, 
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS b, 
INFORMATION_SCHEMA.KEY_COLUMN_USAGE c, 
INFORMATION_SCHEMA.KEY_COLUMN_USAGE d 
WHERE a.CONSTRAINT_TYPE = &#039;FOREIGN KEY&#039; 
and a.CONSTRAINT_NAME = b.CONSTRAINT_NAME 
and a.CONSTRAINT_NAME = c.CONSTRAINT_NAME 
and b.UNIQUE_CONSTRAINT_NAME = d.CONSTRAINT_NAME 
and c.ORDINAL_POSITION = d.ORDINAL_POSITION 
ORDER BY a.CONSTRAINT_NAME, c.ORDINAL_POSITION 

Best regards,


Heiner</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>Your sql seems to have problems with foreign keys consisting of several columns. I get for example:</p>
<p>IE_FK_ADDRESS_USER  IE_ADDRESS  INST_ID         IE_USER  HOLDER_ID<br />
IE_FK_ADDRESS_USER  IE_ADDRESS  INST_ID         IE_USER  INST_ID<br />
IE_FK_ADDRESS_USER  IE_ADDRESS  USER_HOLDER_ID  IE_USER  HOLDER_ID<br />
IE_FK_ADDRESS_USER  IE_ADDRESS  USER_HOLDER_ID  IE_USER  INST_ID</p>
<p>but just the second and third row are okay. I am far from being an sql expert, but the following select returns the correct result for my database:</p>
<p>SELECT<br />
ConstraintName = a.CONSTRAINT_NAME,<br />
FromTable = c.TABLE_NAME,<br />
FromColumn = c.COLUMN_NAME,<br />
ToTable = d.TABLE_NAME,<br />
ToColumn = d.COLUMN_NAME<br />
FROM<br />
INFORMATION_SCHEMA.TABLE_CONSTRAINTS a,<br />
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS b,<br />
INFORMATION_SCHEMA.KEY_COLUMN_USAGE c,<br />
INFORMATION_SCHEMA.KEY_COLUMN_USAGE d<br />
WHERE a.CONSTRAINT_TYPE = &#8216;FOREIGN KEY&#8217;<br />
and a.CONSTRAINT_NAME = b.CONSTRAINT_NAME<br />
and a.CONSTRAINT_NAME = c.CONSTRAINT_NAME<br />
and b.UNIQUE_CONSTRAINT_NAME = d.CONSTRAINT_NAME<br />
and c.ORDINAL_POSITION = d.ORDINAL_POSITION<br />
ORDER BY a.CONSTRAINT_NAME, c.ORDINAL_POSITION </p>
<p>Best regards,</p>
<p>Heiner</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached (User agent is rejected)
Database Caching 2/8 queries in 0.486 seconds using memcached
Object Caching 257/261 objects using memcached

Served from: www.tech-recipes.com @ 2012-02-10 12:00:01 -->
