all groups > sql server programming > february 2007 >
You're in the

sql server programming

group:

why mulitple primary keys allowed in a table


why mulitple primary keys allowed in a table loufuki NO[at]SPAM gmail.com
2/5/2007 10:41:48 PM
sql server programming: in sql 2000, you are allowed to create multiple primary key on
different column.
I don't understand this.
Can anyone please explain.
Re: why mulitple primary keys allowed in a table Tom Cooper
2/6/2007 1:57:57 AM
A table can have only one primary key. However, a primary key can have more
than one column. For example, suppose you have a table of order lines. One
common choice in that case is a primary key consisting of OrderNumber and
LineNumber. OrderNumber is not sufficient to identify a particular
orderline since an order can have many line items on it, and LineNumber is
not sufficient to identify an orderline since many orders will have a line
number 1. But the combination of OrderNumber and LineNumber is unique to
each orderline and thus makes a candidate key that can be used as the
primary key.

Tom

[quoted text, click to view]

AddThis Social Bookmark Button