Alex Rivera | Logout

What are the pros and cons of using multi column primary keys?

Asked 2010-02-05T00:58:22.107
25

I would like to see an example of:

  • When this is appropriate
  • When this is not appropriate

Is there a time when the choice of database would make a difference to the above examples?

Edit
Report

1 Answer

5

I think it's almost always better (from an application developer standpoint, at least) to make the primary key an auto-generated key, and create a UNIQUE constraint and an index on the multiple columns.

  • With a single auto-generated primary key, you'll be able to easily add references to this table from other tables.
  • Auto-generated primary keys work more simply with ORM libraries.
  • Also, if your uniqueness constraints change in the future, you don't have to change the existing primary keys.

I've run into several headache-inducing situations because a DBA thought that a multiple-column primary key would always be sufficient, and future requirements changes proved this incorrect.

answered 2010-02-05T01:11:41.097

Your Answer