Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two Fields - One Primary Key

Status
Not open for further replies.

Onyxpurr

Programmer
Feb 24, 2003
476
US
I thought in SQL Server 97 that I can create a primary key with two fields?

Please let me know if this is correct. My DBA is saying no.

Thanks!!
 
A primary key constraint can contain more than one column, so you are correct.
 
Hi, well you can with SQL 2000 and if I remember correcly you was able to do it in SQL 6.5, so there is no reason you can't do it in the version 7.



Mal'chik [bigglasses]
 
However, just because you can do it doesn't mean you should do it. It is often better performance wise to use an identity column as the proimary key and put a cunique constraint onthe two fields in combination. Takes less storage space for the foreign keys and joins on number fields are much faster.
 
Thank you.

I went researching after seeing responses and put a request into my dba for the following:

CONSTRAINT table_key PRIMARY KEY (a, b)

Is that right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top