﻿<?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 Kiran Kumar  / Getting unique or primary key columns for a given table / 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>Fri, 24 May 2013 15:36:19 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Getting unique or primary key columns for a given table</title><link>http://www.sqlservercentral.com/Forums/Topic617744-1433-1.aspx</link><description>Kiran -Do you have a version of your query for MS SQL 2000?</description><pubDate>Fri, 02 Jan 2009 08:25:19 GMT</pubDate><dc:creator>irene.floyd</dc:creator></item><item><title>RE: Getting unique or primary key columns for a given table</title><link>http://www.sqlservercentral.com/Forums/Topic617744-1433-1.aspx</link><description>Yes ...this code will only work with 2005/8 I think...</description><pubDate>Fri, 02 Jan 2009 08:17:12 GMT</pubDate><dc:creator>peterhails</dc:creator></item><item><title>RE: Getting unique or primary key columns for a given table</title><link>http://www.sqlservercentral.com/Forums/Topic617744-1433-1.aspx</link><description>What version of SQL are you using?I got these error messages when I tried your code in MS SQL 2000:Server: Msg 208, Level 16, State 1, Line 5Invalid object name 'sys.columns'.Server: Msg 208, Level 16, State 1, Line 5Invalid object name 'sys.key_constraints'.</description><pubDate>Fri, 02 Jan 2009 08:00:57 GMT</pubDate><dc:creator>irene.floyd</dc:creator></item><item><title>RE: Getting unique or primary key columns for a given table</title><link>http://www.sqlservercentral.com/Forums/Topic617744-1433-1.aspx</link><description>Thats great Kiran...For interest I have modified this to just show Unique cols plus PK for the param table:create PROCEDURE [dbo].[GetUniqueCols]@table_name nvarchar(50)ASselect    c.name as [Column_Name],    kc.name as [Constraint_Name],    object_name(c.object_id) as [Table_Name]from sys.columns cjoin sys.key_constraints kcon (c.column_id = kc.unique_index_id and c.object_id = kc.parent_object_id)where kc.type='UQ' or kc.type = 'PK'and c.object_id = object_id(@table_name)GROUP BY c.name,kc.NAME, object_name(c.object_id)Having object_name(c.object_id)=@table_name</description><pubDate>Fri, 02 Jan 2009 02:30:23 GMT</pubDate><dc:creator>peterhails</dc:creator></item><item><title>Getting unique or primary key columns for a given table</title><link>http://www.sqlservercentral.com/Forums/Topic617744-1433-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/PK/65218/"&gt;Getting unique or primary key columns for a given table&lt;/A&gt;[/B]</description><pubDate>Thu, 11 Dec 2008 04:27:35 GMT</pubDate><dc:creator>Kiran-339615</dc:creator></item></channel></rss>