Should a database table always have primary keys?

user34537 picture user34537 · May 6, 2009 · Viewed 30.6k times · Source

Should I always have a primary key in my database tables?

Let's take the SO tagging. You can see the tag in any revision, its likely to be in a tag_rev table with the postID and revision number. Would I need a PK for that?

Also since it is in a rev table and not currently use the tags should be a blob of tagIDs instead of multiple entries of multiple post_id tagid pair?

Answer

mmx picture mmx · May 6, 2009

A table should have a primary key so that you could identify each row uniquely with it.

Technically, you can have tables without a primary key, but you'll be breaking good database design rules.