mysql primary key id debate

Stuart Jansen sjansen at
Thu Dec 29 16:48:39 MST 2005

On Thu, 2005-12-29 at 16:17 -0700, Roberto Mello wrote:
> On Thu, Dec 29, 2005 at 04:10:26PM -0700, kirk wrote:
> > Myself and three other programers have been arguing (for well over an hour) 
> > about naming the primary key in a mysql database table.
> > I was wondering what other people name it.
> > 
> > The argument is to name it "id" or another name like "client_id".
> > I like client_id because then the primary key name matches the foreign key 
> > in another table.
> > 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.
> > Thanks.

Kirk, Ruby on Rails uses the naming convention your co-workers suggest.
As for wasting more than an hour arguing about it, I'm sure your
employer will be overjoyed to hear that you've wasted so much time
discussing it.

It's like indentation, just pick something then be consistent. If you
don't like what is decided, suck it up, be a man and follow the
standard. (If you do like it, be sure to rub your victory in every time
a heathen co-worker tries to suggest something else.)

> I prefer to name it foo_id personally, for readability, because 
> it helps in queries.

Roberto, I don't see how it helps in queries.

SELECT foo, bar FROM foo_table AS foo, bar_table AS bar
  WHERE =;

Sure, it's a tiny bit more verbose, but so what?

Stuart Jansen              e-mail/jabber: sjansen at
                           google talk:   stuart.jansen at
:0                         # copy & paste for your convenience
* ^From:.*sjansen@
/dev/null                  # /ignore sjansen!*@*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : 

More information about the PLUG mailing list