mysql primary key id debate

Gabriel Gunderson gabe at
Thu Dec 29 16:43:42 MST 2005

kirk wrote:
 > Myself and three other programers have been arguing (for well over an 
 > about naming the primary key in a mysql database table.

Must be a slow day.

 > I was wondering what other people name it.

Here is my take...

If the two match then you have to scope it so it's not ambiguous.  For 
example, client_id and client_id may "match" but when writing SQL a 
"match" is no good.  You'll end up having to write the tables name also.

SELECT ... clients.client_id ... jobs.clients_id...;

If you end up having to add the table name anyway, then you don't need 
the long ID name because you get everything you need with...

SELECT ... ... jobs.clients_id;

It saves a little bit on typing and redundancy.  It also seems to be a 
bit more clear.

 > My coworker likes just the name id because then he can have a base class
 > called getId()
 > that returns the value of the id column of that table.

Everyone has their reasons.  In the end, none of them matter because it 
comes down to personal taste.  Now get back to work ;)


More information about the PLUG mailing list