views:

40

answers:

2

Say you have a table named Product and it has an auto-number/identity column. Do you name it simply Id or do you name it ProductId or Product_Id? Please explain why.

+1  A: 

Just ID. It's shorter and plays nicely with Wizardby and other code-generation tools/automappers/etc.

Anton Gogolev
and the table name says already what is stored in. why duplicate that information to the fields.
Bernd Ott
+1  A: 

There is no clear answer because it depends on your other tools, your existing naming conventions, and even personal preference. For example, you might use an ORM that expects "ID" on every table. Personally, I would go with "ProductID" because it makes it easier to read queries (for me) and I don't like underscores.

One argument that is completely wrong is that "ID" saves typing time: you spend a lot more time reading code than writing it, so you should always prioritize readable code over saving keystrokes.

If you want some 'real' references, check out Joe Celko's book on SQL programming style and/or ISO 11179.

Pondlife