mysql primary key id debate

Ross Werner ross at agilestudios.com
Fri Dec 30 10:07:32 MST 2005


On Thu, 29 Dec 2005, Gary Thornock wrote:
> I prefer client_id, both because the name matches when I use the
> key as a foreign key in another table,

I understand this justification, although I personally prefer "id", but

> and because there are frequently multiple $x_id fields in a table, and 
> it's useful to distinguish between them.

I don't understand this justification. Are you saying that a table 
frequently has more than one primary key? Or are you saying that you 
prefer foreign keys to be of the format $x_id?

If the latter, unless I misunderstood, that was never under debate--I 
think everyone prefers $x_id for foreign keys. The argument is between:

(Table "foo" with two foreign key columns)
foo.foo_id
foo.bar_id
foo.baz_id

vs.

foo.id
foo.bar_id
foo.baz_id

> As for having a base getID function, why not have one that knows
> that the primary key field is always $tablename_id?

I agree; in actual code you can have it always prefix the table name when 
calling getID() or the like. This isn't really an issue IMO.

 	~ Ross



More information about the PLUG mailing list