SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 selecting by primary key
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mack77
Starting Member

2 Posts

Posted - 07/11/2001 :  17:06:23  Show Profile  Reply with Quote
how do you figure out which column in a know table is the primary key column

JustinBigelow
SQL Gigolo

USA
1157 Posts

Posted - 07/11/2001 :  17:21:23  Show Profile  Reply with Quote
Not sure what a "know table" is but you can get the primary key with...

sp_help tablename

Justin





Edited by - justinbigelow on 07/11/2001 17:23:02
Go to Top of Page

mack77
Starting Member

2 Posts

Posted - 07/12/2001 :  10:22:53  Show Profile  Reply with Quote
ok i got that to work but is there anyway i can split the two result sets that returns

Go to Top of Page

JustinBigelow
SQL Gigolo

USA
1157 Posts

Posted - 07/12/2001 :  10:51:29  Show Profile  Reply with Quote
OK you confused me again (not that it's hard to do ) what do you mean by two result sets? I only get one when I run it.

It may not matter. I looked up some of the information_schema views and came up with the following.

select t1.column_name, t1.constraint_name
from information_schema.constraint_column_usage t1
inner join information_schema.table_constraints t2
on t1.table_name = t2.table_name
and t1.constraint_name = t2.constraint_name
where t2.table_name = 'authors'
and t2.constraint_type = 'primary key'

This will give you the name of the column and constraint for the primary key of the authors table in the pubs database. Put your table name in it's place and you should be good to go.

HTH,
Justin

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000