Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming primary keys "id" vs "something_id" in SQL [closed]

I'm wondering what the best practice is for naming primary/unique keys in a database with many tables. Should you always just call each table's primary key id or is ok to not have an id field in each table and just name each of them something1_id, something2_id, etc?

like image 920
tim peterson Avatar asked May 03 '12 18:05

tim peterson


3 Answers

Whatever you do, pick one or the other and stick to that standard. There are pros and cons for each.

I prefer SomethingID but other people prefer just ID. In the system I work with there are well over a thousand tables and having the PK and the FK have the exact same names makes things easier.

like image 153
KM. Avatar answered Sep 19 '22 17:09

KM.


It's personal preference. At the end of the day it makes absolutely no difference. I personally prefer using just Id as I find referring to the field (let's say Customer table and Id field) Customer.CustomerId to be cumbersome, where Customer.Id seems to make more sense.

like image 40
Brendan Avatar answered Sep 19 '22 17:09

Brendan


It is a matter of preference; however, there is an advantage to using (something)ID in that column names become less ambiguous when you are doing joins between tables.

like image 45
Jonathan Wood Avatar answered Sep 22 '22 17:09

Jonathan Wood