<?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; Generate Foreign Key Scripts For Database</title>
	<atom:link href="http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-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: Jeff</title>
		<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/#comment-57678</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 17 Nov 2009 23:28:06 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=573#comment-57678</guid>
		<description>I like this script and can see where it can save me a lot of time.  However I can not get it to work on any schema other then dbo.  What change can I make to use scheams?</description>
		<content:encoded><![CDATA[<p>I like this script and can see where it can save me a lot of time.  However I can not get it to work on any schema other then dbo.  What change can I make to use scheams?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/#comment-52038</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Tue, 19 May 2009 03:08:09 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=573#comment-52038</guid>
		<description>Hey man...I appreciate this posting.

It saved me a LOT of time and headache.  A lot better than using the generate sql script wizard.

Thanks again.</description>
		<content:encoded><![CDATA[<p>Hey man&#8230;I appreciate this posting.</p>
<p>It saved me a LOT of time and headache.  A lot better than using the generate sql script wizard.</p>
<p>Thanks again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patel</title>
		<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/#comment-50646</link>
		<dc:creator>Patel</dc:creator>
		<pubDate>Tue, 07 Apr 2009 21:33:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=573#comment-50646</guid>
		<description>Raknel - Thanks for the excellent suggestion/script</description>
		<content:encoded><![CDATA[<p>Raknel &#8211; Thanks for the excellent suggestion/script</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: raknel</title>
		<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/#comment-43879</link>
		<dc:creator>raknel</dc:creator>
		<pubDate>Thu, 23 Oct 2008 15:16:44 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=573#comment-43879</guid>
		<description>select  &#039;ALTER TABLE &#039;+object_name(a.parent_object_id)+
    case when a.is_not_trusted = 1 then &#039; WITH NOCHECK &#039;
        else &#039;&#039; end + 
	&#039; ADD CONSTRAINT &#039;+ a.name +
	&#039; FOREIGN KEY (&#039; + c.name + &#039;) REFERENCES &#039; +
	object_name(b.referenced_object_id) +
	&#039; (&#039; + d.name + &#039;)&#039;
from 	sys.foreign_keys a
     	join sys.foreign_key_columns b
                  on a.object_id=b.constraint_object_id
     	join sys.columns c
                  on b.parent_column_id = c.column_id
	         and a.parent_object_id=c.object_id
     	join sys.columns d
                  on b.referenced_column_id = d.column_id
	        and a.referenced_object_id = d.object_id
where   object_name(b.referenced_object_id) in
	(select name from sys.tables)
order by c.name</description>
		<content:encoded><![CDATA[<p>select  &#8216;ALTER TABLE &#8216;+object_name(a.parent_object_id)+<br />
    case when a.is_not_trusted = 1 then &#8216; WITH NOCHECK &#8216;<br />
        else &#8221; end +<br />
	&#8216; ADD CONSTRAINT &#8216;+ a.name +<br />
	&#8216; FOREIGN KEY (&#8216; + c.name + &#8216;) REFERENCES &#8216; +<br />
	object_name(b.referenced_object_id) +<br />
	&#8216; (&#8216; + d.name + &#8216;)&#8217;<br />
from 	sys.foreign_keys a<br />
     	join sys.foreign_key_columns b<br />
                  on a.object_id=b.constraint_object_id<br />
     	join sys.columns c<br />
                  on b.parent_column_id = c.column_id<br />
	         and a.parent_object_id=c.object_id<br />
     	join sys.columns d<br />
                  on b.referenced_column_id = d.column_id<br />
	        and a.referenced_object_id = d.object_id<br />
where   object_name(b.referenced_object_id) in<br />
	(select name from sys.tables)<br />
order by c.name</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shyam Bhavsar</title>
		<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/#comment-41024</link>
		<dc:creator>Shyam Bhavsar</dc:creator>
		<pubDate>Wed, 30 Jul 2008 05:27:28 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=573#comment-41024</guid>
		<description>hello friendz !!

I would like to know about foreign key reference in same database, my problem is - 

I have 2 tables
table 1 - 
CREATE TABLE [dbo].[Increment](
	[Org_Value_ID] [numeric](9, 0) NOT NULL,
	[Ph_Code] [numeric](9, 0) NOT NULL,
	[Sr_No] [int] NOT NULL,
	[Increment_S] [numeric](15,2) NULL,
	[Increment_V] [numeric](15,2) NULL,
CONSTRAINT [PK_Increment] PRIMARY KEY CLUSTERED 
(
	[Org_Value_ID] ASC,
	[Ph_Code] ASC,
	[Sr_No] ASC
)) ON [PRIMARY]


Table 2 - 
CREATE TABLE [dbo].[Org_Value](
	[Org_Value_ID] [numeric](9, 0) NOT NULL,
	[Ph_Code] [numeric](9, 0) NOT NULL,
	[Entitled] [numeric](9, 2) NULL,
 CONSTRAINT [PK_Org_Value] PRIMARY KEY CLUSTERED 
(
	[Org_Value_ID] ASC,
	[Ph_Code] ASC
)) ON [PRIMARY]

I want to add foreign key reference from Org_value to Increment on Org_value_id &amp; Ph_Code

when i tried - 
ALTER TABLE [dbo].[Org_Value]  WITH CHECK ADD  CONSTRAINT [FK_Org_Value_Increment] FOREIGN KEY([Org_value_ID], [Ph_Code]) REFERENCES [dbo].[Increment] ([Org_Value_ID],[Ph_Code])

I am getting error -
There are no primary or candidate keys in the referenced table &#039;dbo.Increment&#039; that match the referencing column list in the foreign key &#039;FK_Org_Value_Increment&#039;.


Please provide some comments, what should i do ?</description>
		<content:encoded><![CDATA[<p>hello friendz !!</p>
<p>I would like to know about foreign key reference in same database, my problem is &#8211; </p>
<p>I have 2 tables<br />
table 1 &#8211;<br />
CREATE TABLE [dbo].[Increment](<br />
	[Org_Value_ID] [numeric](9, 0) NOT NULL,<br />
	[Ph_Code] [numeric](9, 0) NOT NULL,<br />
	[Sr_No] [int] NOT NULL,<br />
	[Increment_S] [numeric](15,2) NULL,<br />
	[Increment_V] [numeric](15,2) NULL,<br />
CONSTRAINT [PK_Increment] PRIMARY KEY CLUSTERED<br />
(<br />
	[Org_Value_ID] ASC,<br />
	[Ph_Code] ASC,<br />
	[Sr_No] ASC<br />
)) ON [PRIMARY]</p>
<p>Table 2 &#8211;<br />
CREATE TABLE [dbo].[Org_Value](<br />
	[Org_Value_ID] [numeric](9, 0) NOT NULL,<br />
	[Ph_Code] [numeric](9, 0) NOT NULL,<br />
	[Entitled] [numeric](9, 2) NULL,<br />
 CONSTRAINT [PK_Org_Value] PRIMARY KEY CLUSTERED<br />
(<br />
	[Org_Value_ID] ASC,<br />
	[Ph_Code] ASC<br />
)) ON [PRIMARY]</p>
<p>I want to add foreign key reference from Org_value to Increment on Org_value_id &amp; Ph_Code</p>
<p>when i tried &#8211;<br />
ALTER TABLE [dbo].[Org_Value]  WITH CHECK ADD  CONSTRAINT [FK_Org_Value_Increment] FOREIGN KEY([Org_value_ID], [Ph_Code]) REFERENCES [dbo].[Increment] ([Org_Value_ID],[Ph_Code])</p>
<p>I am getting error -<br />
There are no primary or candidate keys in the referenced table &#8216;dbo.Increment&#8217; that match the referencing column list in the foreign key &#8216;FK_Org_Value_Increment&#8217;.</p>
<p>Please provide some comments, what should i do ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: doc_sewell</title>
		<link>http://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/#comment-39302</link>
		<dc:creator>doc_sewell</dc:creator>
		<pubDate>Wed, 18 Jun 2008 02:26:09 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=573#comment-39302</guid>
		<description>so how come he says cusror instead of cursor?  What if I just want to show all the tables with FKs and the FK names and the status if they are enabled or disabled?</description>
		<content:encoded><![CDATA[<p>so how come he says cusror instead of cursor?  What if I just want to show all the tables with FKs and the FK names and the status if they are enabled or disabled?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
