What is the best practice for naming the column that is the primary key for a mysql table? I have seen two ways:
- ‘id’
- tableName_id (Where tableName is substituted for the name of the table).
I would have thought just id would suffice, because you can still uniquely identify the column by selecting the column proceeded by a period and the table name (i.e. for the column ‘id’ in the table ‘cars’, you could select it as cars.id)
Or am I over-thinking it all?
I usually name them as [tblname]_id. The reason is simple. Let’s say I have two tables:
Now I can join them with MySQLs USING-syntax and save a few characters for each join:
Of course, this is all mostly subjective.