Short answer: yes.
Long answer:
- You need your table to be joinable on something
- If you want your table to be clustered, you need some kind of a primary key.
- If your table design does not need a primary key, rethink your design: most probably, you are missing something. Why keep identical records?
In MySQL
, the InnoDB
storage engine always creates a PRIMARY KEY
if you didn't specify it explicitly, thus making an extra column you don't have access to.
Note that a PRIMARY KEY
can be composite.
If you have a many-to-many link table, you create the PRIMARY KEY
on all fields involved in the link. Thus you ensure that you don't have two or more records describing one link.
Besides the logical consistency issues, most RDBMS
engines will benefit from including these fields in an UNIQUE
index.
And since any PRIMARY KEY
involves creating a UNIQUE
index, you should declare it and get both logical consistency and performance.
See this article in my blog for why you should always create a UNIQUE
index on unique data:
P. S. There are some very, very special cases where you don't need a primary key.
Mostly they include log tables which don't have ANY
indexes for performance reasons.