I have table Widgets and table Persons
both of them contains Identity column ( seed)
what is the recommended naming convention for the identity column ?
is it "id
" ( for both tables ) :
Widgets.Id
Persons.Id
or
Widgets.WidgetId
Persons.PersonId
Is there advantages / disadvantages in the former compare to the latter ?
This is one case where I'd go for redundancy and have Thing.ThingID
Otherwise you have to alias it everywhere when you JOIN
Note: this was already done to death and beyond on programmers.se:
Why is naming a table's Primary Key column “Id” considered bad practice?
The best practice for this is to preface with the table name.
This will make it much clearer when joining which field you are referring to in the SELECT
list.
It also makes accidental bad JOIN
conditions impossible, i.e.
JOIN TableA ON ID = TableA.ID
As a rule, duplicate field names across tables should be avoided unless they represent identical data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With