mysql primary key id debate
jonathan at carnageblender.com
Thu Dec 29 16:57:29 MST 2005
On Thu, 29 Dec 2005 16:17:53 -0700, "Roberto Mello"
<rmello at fslc.usu.edu> said:
> 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").
You're right, it's basically a matter of taste. Myself, I prefer simply
"id." I find this to be
(a) less redundant (for similar reasons, I dislike Hungarian notation)
(b) more consistent -- if this is such a good idea, then you should
really be prefixing all other columns with the tablename too! (Some
people actually do this. It drives me nuts to work in their databases)
(c) far less annoying when having to write code (SQL or otherwise)
dealing with that key. (How many times do you really want to type out
"bid.classified_auction_bid_id" instead of "bid.id?" Okay,
introspecting editors help. It's still ugly!)
On the other hand, having prefixed ids is convenient when writing
natural joins. For me though writing the occasional natural join "the
hard way" is much less annoying than having to constantly type out
C++ is history repeated as tragedy. Java is history repeated as farce. --Scott McKay
More information about the PLUG