﻿<?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 / Article Discussions by Author / Discuss content posted by Furanshizuku  / how get primary key in any database / 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>Wed, 19 Jun 2013 05:40:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: how get primary key in any database</title><link>http://www.sqlservercentral.com/Forums/Topic641675-1465-1.aspx</link><description>To be clearer, as you can name the primary key anything you want the statements from the article would miss any that do not begin with 'PK'.[code]declare @name_pk varchar(255)select @name_pk = name from sysindexes where id in (select id from sysobjects where name = 'table_name') and name like 'PK%'execute ('alter table table_name drop constraint ' + @name_pk)[/code]So to get the name of the Primary Key Constraint without this restriction, using the same 'table_name' substitution:[code]declare @name_pk varchar(255)SELECT @name_pk = constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_type = 'PRIMARY KEY' and Table_name = 'table_name'Print 'pk ' + @name_pk  -- show the results/* or use the execute as in the original */-- execute ('alter table table_name drop constraint ' + @name_pk)[/code]Toni</description><pubDate>Thu, 29 Jan 2009 05:48:40 GMT</pubDate><dc:creator>toniupstny</dc:creator></item><item><title>RE: how get primary key in any database</title><link>http://www.sqlservercentral.com/Forums/Topic641675-1465-1.aspx</link><description>This information can be gotten despite how the constraint is named this way:[code]SELECT Table_name, constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_type = 'PRIMARY KEY'[/code]then you can use the table_name and constraint_name to do what you wish.Toni</description><pubDate>Thu, 29 Jan 2009 05:29:41 GMT</pubDate><dc:creator>toniupstny</dc:creator></item><item><title>how get primary key in any database</title><link>http://www.sqlservercentral.com/Forums/Topic641675-1465-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Primary+key/65628/"&gt;how get primary key in any database&lt;/A&gt;[/B]</description><pubDate>Thu, 22 Jan 2009 07:04:28 GMT</pubDate><dc:creator>Furanshizuku</dc:creator></item></channel></rss>