mysql primary key id debate
rmello at fslc.usu.edu
Thu Dec 29 16:17:53 MST 2005
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.
It seems to be a shibboleth . Pick one and be consistent.
I prefer to name it foo_id personally, for readability, because
it helps in queries.
As for the base class thing, if you're consistent in prepending
"table_name" to _id, then it should be just as easy to have a base class
method that gets the id for a certain tuple ("row").
Dente lupus, cornu taurus petit.
More information about the PLUG