<?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; Two Methods to Retrieve List of Primary Keys and Foreign Keys of Database</title>
	<atom:link href="http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Mon, 13 Feb 2012 15:11:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: scottie2hottie</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-151581</link>
		<dc:creator><![CDATA[scottie2hottie]]></dc:creator>
		<pubDate>Fri, 29 Jul 2011 13:12:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-151581</guid>
		<description><![CDATA[SELECT OBJECT_NAME(parent_object_id) Parent,
	   COL_NAME(parent_object_id, parent_column_id) ParentCol,
	   OBJECT_NAME(referenced_object_id) Child,
	   COL_NAME(referenced_object_id, referenced_column_id) ChildCol
FROM sys.foreign_key_columns]]></description>
		<content:encoded><![CDATA[<p>SELECT OBJECT_NAME(parent_object_id) Parent,<br />
	   COL_NAME(parent_object_id, parent_column_id) ParentCol,<br />
	   OBJECT_NAME(referenced_object_id) Child,<br />
	   COL_NAME(referenced_object_id, referenced_column_id) ChildCol<br />
FROM sys.foreign_key_columns</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill C</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-57792</link>
		<dc:creator><![CDATA[Bill C]]></dc:creator>
		<pubDate>Sun, 22 Nov 2009 04:06:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-57792</guid>
		<description><![CDATA[This retrieves the key names, but does not retrieve the field names of the keys. We need this for ASP.NET to dynamically generate the INSERT, UPDATE, and DELETE commands for a web interface that can edit data of any server database.]]></description>
		<content:encoded><![CDATA[<p>This retrieves the key names, but does not retrieve the field names of the keys. We need this for ASP.NET to dynamically generate the INSERT, UPDATE, and DELETE commands for a web interface that can edit data of any server database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Puzzle – Write Script to Generate Primary Key and Foreign Key Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53975</link>
		<dc:creator><![CDATA[SQL SERVER – Puzzle – Write Script to Generate Primary Key and Foreign Key Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Thu, 23 Jul 2009 01:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53975</guid>
		<description><![CDATA[[...] of Primary Key or Foreign Key of database. I have already written an article for the same here : SQL SERVER – Two Methods to Retrieve List of Primary Keys and Foreign Keys of Database . I am looking for T-SQL script that generates Primary Key from the existing table for all tables [...]]]></description>
		<content:encoded><![CDATA[<p>[...] of Primary Key or Foreign Key of database. I have already written an article for the same here : SQL SERVER – Two Methods to Retrieve List of Primary Keys and Foreign Keys of Database . I am looking for T-SQL script that generates Primary Key from the existing table for all tables [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vanda</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53890</link>
		<dc:creator><![CDATA[John Vanda]]></dc:creator>
		<pubDate>Mon, 20 Jul 2009 17:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53890</guid>
		<description><![CDATA[My response could be excluding a few; Not sure where though.  My response boils down to:

SELECT ...
FROM sys.objects
LEFT JOIN ... {FK subquery}
LEFT JOIN ... {PK subquery}
WHERE type_desc IN (’FOREIGN_KEY_CONSTRAINT’,&#039;PRIMARY_KEY_CONSTRAINT’)
ORDER BY [TableName] ASC

Each of the left join sets should contain less records than the sys.objects set, but, since it&#039;s a left join, the set from sys.objects shouldn&#039;t be excluding anything.  I could be missing something...]]></description>
		<content:encoded><![CDATA[<p>My response could be excluding a few; Not sure where though.  My response boils down to:</p>
<p>SELECT &#8230;<br />
FROM sys.objects<br />
LEFT JOIN &#8230; {FK subquery}<br />
LEFT JOIN &#8230; {PK subquery}<br />
WHERE type_desc IN (’FOREIGN_KEY_CONSTRAINT’,&#8217;PRIMARY_KEY_CONSTRAINT’)<br />
ORDER BY [TableName] ASC</p>
<p>Each of the left join sets should contain less records than the sys.objects set, but, since it&#8217;s a left join, the set from sys.objects shouldn&#8217;t be excluding anything.  I could be missing something&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Behtash Moradi</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53816</link>
		<dc:creator><![CDATA[Behtash Moradi]]></dc:creator>
		<pubDate>Sat, 18 Jul 2009 09:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53816</guid>
		<description><![CDATA[I guess something is wrong with one of suggested methods?

I ran both methods on same database and found different result.First one returned 267 record and second ones returned only 254?

Is it possible?

Thanks
BEHTASH]]></description>
		<content:encoded><![CDATA[<p>I guess something is wrong with one of suggested methods?</p>
<p>I ran both methods on same database and found different result.First one returned 267 record and second ones returned only 254?</p>
<p>Is it possible?</p>
<p>Thanks<br />
BEHTASH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: celio</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53807</link>
		<dc:creator><![CDATA[celio]]></dc:creator>
		<pubDate>Fri, 17 Jul 2009 19:08:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53807</guid>
		<description><![CDATA[I prefer method 3 ! what is the method 3 ??]]></description>
		<content:encoded><![CDATA[<p>I prefer method 3 ! what is the method 3 ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vanda</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53805</link>
		<dc:creator><![CDATA[John Vanda]]></dc:creator>
		<pubDate>Fri, 17 Jul 2009 18:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53805</guid>
		<description><![CDATA[When you copy/paste the code above, it&#039;s changing some of the sql ticks and double-ticks to apostrophe&#039;s, backwards apostrophes, and quotations.  You&#039;ll have to replace those out to run the query.]]></description>
		<content:encoded><![CDATA[<p>When you copy/paste the code above, it&#8217;s changing some of the sql ticks and double-ticks to apostrophe&#8217;s, backwards apostrophes, and quotations.  You&#8217;ll have to replace those out to run the query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vanda</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53804</link>
		<dc:creator><![CDATA[John Vanda]]></dc:creator>
		<pubDate>Fri, 17 Jul 2009 18:26:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53804</guid>
		<description><![CDATA[This is a bit long winded, but it was a fun hour making it.

SELECT OBJECT_NAME(o.[object_id]) AS NameofConstraint,
	   SCHEMA_NAME(schema_id) AS SchemaName,
	   OBJECT_NAME(parent_object_id) AS TableName,
		type_desc AS ConstraintType,
	CASE 
		WHEN fk.ForeignKey_Name IS NOT NULL THEN 
			&#039;ALTER TABLE [&#039; + SCHEMA_NAME([schema_id]) + &#039;].[&#039; 
			+ OBJECT_NAME([parent_object_id])+ &#039;]  WITH NOCHECK ADD  CONSTRAINT [&#039; 
			+ [ForeignKey_Name] + &#039;] FOREIGN KEY([&#039; + fk.name + &#039;]) REFERENCES [&#039; 
			+ fk.[Table_Schema] + &#039;].[&#039; + fk.referenced_table + &#039;]([&#039; 
			+ fk.referencedcolumn + &#039;])&#039;
		WHEN fk.ForeignKey_Name IS NULL THEN
		N&#039;ALTER TABLE [&#039; + pk.table_schema  + &#039;].[&#039; +  pk.table_name + &#039;] ADD  CONSTRAINT [&#039; 
			+  pk.NAME + &#039;] PRIMARY KEY CLUSTERED ([&#039; + pk.[column]  + &#039;] &#039; +  
			+  CASE
				 WHEN pk.is_desc = 0 THEN &#039;ASC&#039;
				 ELSE &#039;DESC&#039;
			   END
			+&#039;)WITH 
			(   PAD_INDEX  = &#039; + CASE
									WHEN pk.PadIndex = 0 THEN &#039;OFF&#039;
									ELSE &#039;ON&#039;									
								 END  
		   + &#039;, STATISTICS_NORECOMPUTE  = &#039; +	CASE
													WHEN pk.NoAutomaticRecomputation = 0 THEN &#039;OFF&#039;
													ELSE &#039;ON&#039;
												END
		   + &#039;, SORT_IN_TEMPDB = OFF&#039; +   
		   + &#039;, IGNORE_DUP_KEY = &#039; +	CASE
											WHEN pk.IgnoreDuplicateKeys = 0 THEN &#039;OFF&#039;
											ELSE &#039;ON&#039;
										END
		   +&#039;, ONLINE = OFF&#039; + 
		   +&#039;, ALLOW_ROW_LOCKS  = &#039; +	CASE
											WHEN pk.DisallowRowLocks = 0 THEN &#039;OFF&#039;
											ELSE &#039;ON&#039;
										END
									
		   +&#039;, ALLOW_PAGE_LOCKS  = &#039; +	CASE
											WHEN pk.DisallowPageLocks = 0 THEN &#039;OFF&#039;
											ELSE &#039;ON&#039;
										END
		   +&#039;, FILLFACTOR = &#039; + CASE
									WHEN pk.[FillFactor] = 0 THEN &#039;100&#039;
									ELSE CONVERT(NVARCHAR, pk.[FillFactor])
								END
		   +&#039;) ON [&#039; + pk.[filegroup]
		   +&#039;]&#039;
		 END [create_statement]	 
FROM sys.objects o
LEFT JOIN ( SELECT
			cstr.[object_id],
			SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
			tbl.name AS [Table_Name],
			cstr.name AS [ForeignKey_Name],
			fk.constraint_column_id AS [ID],
			cfk.name AS [Name],
			crk.name AS [ReferencedColumn],
			OBJECT_NAME(fk.referenced_object_id) [referenced_table]
			FROM sys.tables AS tbl
			INNER JOIN sys.foreign_keys AS cstr ON cstr.parent_object_id=tbl.[object_id]
			INNER JOIN sys.foreign_key_columns AS fk ON fk.constraint_object_id=cstr.[object_id]
			INNER JOIN sys.columns AS cfk ON fk.parent_column_id = cfk.column_id and fk.parent_object_id = cfk.[object_id]
			INNER JOIN sys.columns AS crk ON fk.referenced_column_id = crk.column_id and fk.referenced_object_id = crk.[object_id]) fk ON fk.[object_id] = o.[object_id]
LEFT JOIN ( SELECT
			SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
			tbl.name AS [Table_Name],
			OBJECT_ID(tbl.[name]) [table_id],
			i.name AS [Name],
			CASE WHEN &#039;FG&#039;=dsi.type THEN dsi.name ELSE N&#039;&#039; END AS [FileGroup],
			i.ignore_dup_key AS [IgnoreDuplicateKeys],
			i.fill_factor AS [FillFactor],
			CAST(INDEXPROPERTY(i.[object_id], i.name, N&#039;IsPadIndex&#039;) AS bit) AS [PadIndex],
			~i.allow_row_locks AS [DisallowRowLocks],
			~i.allow_page_locks AS [DisallowPageLocks],
			s.no_recompute AS [NoAutomaticRecomputation],
			c.[column],
			c.[is_desc]
			FROM
			sys.tables AS tbl
			INNER JOIN sys.indexes AS i ON (i.index_id &gt; 0 and i.is_hypothetical = 0) AND (i.[object_id]=tbl.[object_id])
			INNER JOIN (
						SELECT ic.[object_id], c.[name] [column], ic.is_descending_key [is_desc]
						FROM sys.index_columns ic
						INNER JOIN sys.indexes i ON i.[object_id] = ic.[object_id] AND i.index_id = 1 AND ic.index_id = 1 
						INNER JOIN sys.tables t ON t.[object_id] = ic.[object_id]
						INNER JOIN sys.columns c ON c.[object_id] = t.[object_id] AND c.column_id = ic.column_id
						) AS c ON c.[object_id] = i.[object_id]
			LEFT OUTER JOIN sys.key_constraints AS k ON k.parent_object_id = i.[object_id] AND k.unique_index_id = i.index_id
			LEFT OUTER JOIN sys.data_spaces AS dsi ON dsi.data_space_id = i.data_space_id
			LEFT OUTER JOIN sys.xml_indexes AS xi ON xi.[object_id] = i.[object_id] AND xi.index_id = i.index_id
			LEFT OUTER JOIN sys.stats AS s ON s.stats_id = i.index_id AND s.[object_id] = i.[object_id]
			WHERE k.TYPE = &#039;PK&#039;
		) pk ON o.[parent_object_id] = pk.table_id
WHERE type_desc IN (&#039;FOREIGN_KEY_CONSTRAINT&#039;,&#039;PRIMARY_KEY_CONSTRAINT&#039;)
ORDER BY [TableName] asc
GO]]></description>
		<content:encoded><![CDATA[<p>This is a bit long winded, but it was a fun hour making it.</p>
<p>SELECT OBJECT_NAME(o.[object_id]) AS NameofConstraint,<br />
	   SCHEMA_NAME(schema_id) AS SchemaName,<br />
	   OBJECT_NAME(parent_object_id) AS TableName,<br />
		type_desc AS ConstraintType,<br />
	CASE<br />
		WHEN fk.ForeignKey_Name IS NOT NULL THEN<br />
			&#8216;ALTER TABLE [' + SCHEMA_NAME([schema_id]) + &#8216;].['<br />
			+ OBJECT_NAME([parent_object_id])+ &#8216;]  WITH NOCHECK ADD  CONSTRAINT ['<br />
			+ [ForeignKey_Name] + &#8216;] FOREIGN KEY([' + fk.name + ']) REFERENCES ['<br />
			+ fk.[Table_Schema] + &#8216;].[' + fk.referenced_table + '](['<br />
			+ fk.referencedcolumn + '])&#8217;<br />
		WHEN fk.ForeignKey_Name IS NULL THEN<br />
		N&#8217;ALTER TABLE [' + pk.table_schema  + '].[' +  pk.table_name + '] ADD  CONSTRAINT ['<br />
			+  pk.NAME + '] PRIMARY KEY CLUSTERED ([' + pk.[column]  + &#8216;] &#8216; +<br />
			+  CASE<br />
				 WHEN pk.is_desc = 0 THEN &#8216;ASC&#8217;<br />
				 ELSE &#8216;DESC&#8217;<br />
			   END<br />
			+&#8217;)WITH<br />
			(   PAD_INDEX  = &#8216; + CASE<br />
									WHEN pk.PadIndex = 0 THEN &#8216;OFF&#8217;<br />
									ELSE &#8216;ON&#8217;<br />
								 END<br />
		   + &#8216;, STATISTICS_NORECOMPUTE  = &#8216; +	CASE<br />
													WHEN pk.NoAutomaticRecomputation = 0 THEN &#8216;OFF&#8217;<br />
													ELSE &#8216;ON&#8217;<br />
												END<br />
		   + &#8216;, SORT_IN_TEMPDB = OFF&#8217; +<br />
		   + &#8216;, IGNORE_DUP_KEY = &#8216; +	CASE<br />
											WHEN pk.IgnoreDuplicateKeys = 0 THEN &#8216;OFF&#8217;<br />
											ELSE &#8216;ON&#8217;<br />
										END<br />
		   +&#8217;, ONLINE = OFF&#8217; +<br />
		   +&#8217;, ALLOW_ROW_LOCKS  = &#8216; +	CASE<br />
											WHEN pk.DisallowRowLocks = 0 THEN &#8216;OFF&#8217;<br />
											ELSE &#8216;ON&#8217;<br />
										END</p>
<p>		   +&#8217;, ALLOW_PAGE_LOCKS  = &#8216; +	CASE<br />
											WHEN pk.DisallowPageLocks = 0 THEN &#8216;OFF&#8217;<br />
											ELSE &#8216;ON&#8217;<br />
										END<br />
		   +&#8217;, FILLFACTOR = &#8216; + CASE<br />
									WHEN pk.[FillFactor] = 0 THEN &#8217;100&#8242;<br />
									ELSE CONVERT(NVARCHAR, pk.[FillFactor])<br />
								END<br />
		   +&#8217;) ON [' + pk.[filegroup]<br />
		   +&#8217;]&#8217;<br />
		 END [create_statement]<br />
FROM sys.objects o<br />
LEFT JOIN ( SELECT<br />
			cstr.[object_id],<br />
			SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],<br />
			tbl.name AS [Table_Name],<br />
			cstr.name AS [ForeignKey_Name],<br />
			fk.constraint_column_id AS [ID],<br />
			cfk.name AS [Name],<br />
			crk.name AS [ReferencedColumn],<br />
			OBJECT_NAME(fk.referenced_object_id) [referenced_table]<br />
			FROM sys.tables AS tbl<br />
			INNER JOIN sys.foreign_keys AS cstr ON cstr.parent_object_id=tbl.[object_id]<br />
			INNER JOIN sys.foreign_key_columns AS fk ON fk.constraint_object_id=cstr.[object_id]<br />
			INNER JOIN sys.columns AS cfk ON fk.parent_column_id = cfk.column_id and fk.parent_object_id = cfk.[object_id]<br />
			INNER JOIN sys.columns AS crk ON fk.referenced_column_id = crk.column_id and fk.referenced_object_id = crk.[object_id]) fk ON fk.[object_id] = o.[object_id]<br />
LEFT JOIN ( SELECT<br />
			SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],<br />
			tbl.name AS [Table_Name],<br />
			OBJECT_ID(tbl.[name]) [table_id],<br />
			i.name AS [Name],<br />
			CASE WHEN &#8216;FG&#8217;=dsi.type THEN dsi.name ELSE N&#8221; END AS [FileGroup],<br />
			i.ignore_dup_key AS [IgnoreDuplicateKeys],<br />
			i.fill_factor AS [FillFactor],<br />
			CAST(INDEXPROPERTY(i.[object_id], i.name, N&#8217;IsPadIndex&#8217;) AS bit) AS [PadIndex],<br />
			~i.allow_row_locks AS [DisallowRowLocks],<br />
			~i.allow_page_locks AS [DisallowPageLocks],<br />
			s.no_recompute AS [NoAutomaticRecomputation],<br />
			c.[column],<br />
			c.[is_desc]<br />
			FROM<br />
			sys.tables AS tbl<br />
			INNER JOIN sys.indexes AS i ON (i.index_id &gt; 0 and i.is_hypothetical = 0) AND (i.[object_id]=tbl.[object_id])<br />
			INNER JOIN (<br />
						SELECT ic.[object_id], c.[name] [column], ic.is_descending_key [is_desc]<br />
						FROM sys.index_columns ic<br />
						INNER JOIN sys.indexes i ON i.[object_id] = ic.[object_id] AND i.index_id = 1 AND ic.index_id = 1<br />
						INNER JOIN sys.tables t ON t.[object_id] = ic.[object_id]<br />
						INNER JOIN sys.columns c ON c.[object_id] = t.[object_id] AND c.column_id = ic.column_id<br />
						) AS c ON c.[object_id] = i.[object_id]<br />
			LEFT OUTER JOIN sys.key_constraints AS k ON k.parent_object_id = i.[object_id] AND k.unique_index_id = i.index_id<br />
			LEFT OUTER JOIN sys.data_spaces AS dsi ON dsi.data_space_id = i.data_space_id<br />
			LEFT OUTER JOIN sys.xml_indexes AS xi ON xi.[object_id] = i.[object_id] AND xi.index_id = i.index_id<br />
			LEFT OUTER JOIN sys.stats AS s ON s.stats_id = i.index_id AND s.[object_id] = i.[object_id]<br />
			WHERE k.TYPE = &#8216;PK&#8217;<br />
		) pk ON o.[parent_object_id] = pk.table_id<br />
WHERE type_desc IN (&#8216;FOREIGN_KEY_CONSTRAINT&#8217;,'PRIMARY_KEY_CONSTRAINT&#8217;)<br />
ORDER BY [TableName] asc<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ashishgilhotra</title>
		<link>http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/#comment-53789</link>
		<dc:creator><![CDATA[ashishgilhotra]]></dc:creator>
		<pubDate>Fri, 17 Jul 2009 09:14:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5900#comment-53789</guid>
		<description><![CDATA[For Foreign keys which is something difficult ...But i take refrence from your blog so may be its like this....


select &#039;ALTER TABLE &#039;+OBJECT_NAME(f.parent_object_id)+ &#039; ADD CONSTRAINT&#039; + f.name  + &#039; FOREIGN KEY&#039;+&#039;(&#039;+COL_NAME(fc.parent_object_id,fc.parent_column_id)+&#039;)&#039;+&#039;REFRENCES &#039;+OBJECT_NAME (f.referenced_object_id)+&#039;(&#039;+COL_NAME(fc.referenced_object_id,fc.referenced_column_id)+&#039;)&#039; as Scripts
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id]]></description>
		<content:encoded><![CDATA[<p>For Foreign keys which is something difficult &#8230;But i take refrence from your blog so may be its like this&#8230;.</p>
<p>select &#8216;ALTER TABLE &#8216;+OBJECT_NAME(f.parent_object_id)+ &#8216; ADD CONSTRAINT&#8217; + f.name  + &#8216; FOREIGN KEY&#8217;+'(&#8216;+COL_NAME(fc.parent_object_id,fc.parent_column_id)+&#8217;)'+&#8217;REFRENCES &#8216;+OBJECT_NAME (f.referenced_object_id)+&#8217;(&#8216;+COL_NAME(fc.referenced_object_id,fc.referenced_column_id)+&#8217;)&#8217; as Scripts<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</p>
]]></content:encoded>
	</item>
</channel>
</rss>

