Can I have multiple primary keys in a single table?

vaithi picture vaithi · Oct 20, 2008 · Viewed 732.5k times · Source

Can I have multiple primary keys in a single table?

Answer

Adam Pierce picture Adam Pierce · Oct 20, 2008

A Table can have a Composite Primary Key which is a primary key made from two or more columns. For example:

CREATE TABLE userdata (
  userid INT,
  userdataid INT,
  info char(200),
  primary key (userid, userdataid)
);

Update: Here is a link with a more detailed description of composite primary keys.