Composite primary key in sql
by satheeshkumar[ Edit ] 2013-07-04 13:10:07
Composite primary key in sql,
A composite key is a primary key that consists of more than one column. Composite keys are also known as concatenated or aggregate keys.
The primary key must be different for each row of the table. The primary key may not contain a null.
It is defined as follows:
For Example....
CREATE TABLE voting (
QuestionID NUMERIC,
MemberID NUMERIC,
PRIMARY KEY (QuestionID, MemberID)
);
it won't because to use a composite index requires using all the keys from the "left". If an index is on fields (A,B,C) and your criteria is on B and C then that index is of no use to you for that query. So choose from (QuestionID,MemberID) and (MemberID,QuestionID) whichever is most appropriate for how you will use the table.