Is it possible to make two primary keys in one table?

you can only have 1 primary key, but:

  • you can combine more than one column to be the primary key (maybe it's this what you have seen)
  • the primary key don't needs to be an auto-increment, it just has to be unique
  • you can add more than one index to one or more colums to speed up SELECT-statements (but slow down INSERT / UPDATE)
  • those indexes can be marked as unique, wich means they don't let you insert a second row with the same content in the index-fields (just like a primary key)

http://dev.mysql.com/doc/refman/5.1/en/create-table.html

[...] A table can have only one PRIMARY KEY. [...]


No, but you can have other UNIQUE indexes on the table, in addition to the PRIMARY KEY. UNIQUE + NOT NULL is basically the same as a primary key.

What you have seen is probably a composite primary key (more than one column making up the unique key).

Tags:

Mysql