Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 primary key constraints

Author  Topic 

swafophile
Starting Member

3 Posts

Posted - 2010-04-12 : 16:12:35
I have the following constraint creating a primary key referencing three integers in the table that will identify the row as unique only when all three are put together....but this statement doesn't actually create a column for the primary key. Although it runs and says the table was created successfully there is no primary key column. In short, what is the purpose of creating a primary key constraint like this and what can you use it for?

CONSTRAINT Ing_Id PRIMARY KEY (Class_Id, SubClass_Id, Spec_Id)

If instead I wanted to create another column that strung the three integers together (i.e. 1+2+3=123) and use that as the primary key would that be easier?

thanks everyone for any help you can provide

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2010-04-12 : 16:31:01
Correct. Primary Key is a constraint that you enforce on a (set) of columns.. run a select on sys.sysconstraints and join it back to the sys.tables by ID and you can see your constraint. You can also use sp_help 'table' to get all the table information - columns, constraints etc.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

swafophile
Starting Member

3 Posts

Posted - 2010-04-12 : 16:39:39
so i can't reference this primary key (i.e. table_name(Ing_ID)) in other tables? that is what i'm having trouble figuring out...it's just a constraint, not a usable value?

thanks
Go to Top of Page

swafophile
Starting Member

3 Posts

Posted - 2010-04-12 : 16:41:34
okay i think i understand that then....so if i wanted to string the three integers together to create a primary key int how could i do that??

thanks again
Go to Top of Page
   

- Advertisement -