Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When we don't need a primary key for our table?

Will it ever happen that we design a table that doesn't need a primary key?

like image 271
EBAG Avatar asked Mar 31 '11 06:03

EBAG


2 Answers

Yes.

If you have a table that will always be fetched completely, and is being referred-to by zero other tables, such as some kind of standalone settings or configuration table, then there is no point having a primary key, and the argument could be made by some that adding a PK in this situation would be a deception of the normal use of such a table.

It is rare, and probably when it is most often done it is done wrongly, but they do exist, and such instances can be valid.

like image 146
Caleb Hattingh Avatar answered Oct 13 '22 02:10

Caleb Hattingh


No.

The primary key does a lot of stuff behind-the-scenes, even if your application never uses it.

For example: clustering improves efficiency (because heap tables are a mess).

Not to mention, if ANYONE ever has to do something on your table that requires pulling a specific row and you don't have a primary key, you are the bad guy.

like image 45
rockerest Avatar answered Oct 13 '22 01:10

rockerest