﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Discuss content posted by Oxygen / Article Discussions by Author  / SQL Server 2005: Script all Primary Keys / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 03:20:24 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>Oxygen thank you for the post your code got me 80 % of the way there.  I modified your cursor to look for PK in the db that are non clustered then rebuild as clustered. I found 32 in first db looked.  isn't rolling on to a new company great?   SELECT tc.TABLE_NAME, tc.CONSTRAINT_NAME    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc   inner join   sys.indexes i   on tc.CONSTRAINT_NAME= i.name     where CONSTRAINT_TYPE = 'PRIMARY KEY'   and i.index_id &amp;lt;&amp;gt; 1     ORDER BY TABLE_NAME</description><pubDate>Thu, 17 Mar 2011 13:13:04 GMT</pubDate><dc:creator>MudLuck</dc:creator></item><item><title>RE: SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>First thing which is already mentioned that, its not working properly as it dealing FK as PK too, and second thing, what if, i have more then one filegroups ???</description><pubDate>Thu, 23 Jul 2009 04:37:46 GMT</pubDate><dc:creator>lionofdezert</dc:creator></item><item><title>RE: SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>Add:   where CONSTRAINT_TYPE = 'PRIMARY KEY'to avoid scripting out the foreign keys.</description><pubDate>Tue, 12 May 2009 13:26:32 GMT</pubDate><dc:creator>Gordo-174357</dc:creator></item><item><title>RE: SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>i fixed the problem by SELECT TABLE_NAME, CONSTRAINT_NAME    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS    WHERE CONSTRAINT_NAME LIKE '%PK%'  --adding this line   ORDER BY TABLE_NAMEand it worked for me since i have all my primary keys starting with PK_ :D</description><pubDate>Fri, 30 Jan 2009 07:24:59 GMT</pubDate><dc:creator>DBA-640728</dc:creator></item><item><title>RE: SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>It appears to be not handling foreign keys properly and scripting them up as Primary keys.</description><pubDate>Fri, 22 Aug 2008 07:26:45 GMT</pubDate><dc:creator>Putts</dc:creator></item><item><title>RE: SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>You can script the Fill Factor too :Neat the end, just after :   [code]SET @PKSQL = @PKSQL + ')'[/code]  Add :    [code]DECLARE @ff TinyIntSELECT @ff = (select A.fill_factor FROM sys.indexes A Where A.name=@PkName)SET @PKSQL = @PKSQL + ' WITH FILLFACTOR= ' + CAST(@ff as NVARCHAR)[/code]</description><pubDate>Thu, 15 May 2008 01:34:00 GMT</pubDate><dc:creator>Dumas Jean Christophe</dc:creator></item><item><title>SQL Server 2005: Script all Primary Keys</title><link>http://www.sqlservercentral.com/Forums/Topic404359-562-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Index+Management/31892/"&gt;SQL Server 2005: Script all Primary Keys&lt;/A&gt;[/B]</description><pubDate>Sat, 29 Sep 2007 06:09:30 GMT</pubDate><dc:creator>Oxygen</dc:creator></item></channel></rss>