Can I have multiple primary keys in a single table? Can I have multiple primary keys in a single table? database database

Can I have multiple primary keys in a single table?


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.


You can only have one primary key, but you can have multiple columns in your primary key.

You can also have Unique Indexes on your table, which will work a bit like a primary key in that they will enforce unique values, and will speed up querying of those values.


A table can have multiple candidate keys. Each candidate key is a column or set of columns that are UNIQUE, taken together, and also NOT NULL. Thus, specifying values for all the columns of any candidate key is enough to determine that there is one row that meets the criteria, or no rows at all.

Candidate keys are a fundamental concept in the relational data model.

It's common practice, if multiple keys are present in one table, to designate one of the candidate keys as the primary key. It's also common practice to cause any foreign keys to the table to reference the primary key, rather than any other candidate key.

I recommend these practices, but there is nothing in the relational model that requires selecting a primary key among the candidate keys.