Is it preferred to use "Id" as the column name for a primary key or "[TableName]Id" as a naming convention?
Table: Account
Primary Key: Id
-- versus --
Table: Account
Primary Key: AccountId
It seems to be split about 50% / 50% in the implementations that I've seen. What are the advantages and disadvantages in each approach?
Follow-up:
Does it make sense to use one convention in my database, and another on my entities in code? Or should I keep them consistent? How would does this work best in most ORMs?
A primary key, also called a primary keyword, is a key in a relational database that is unique for each record. It is a unique identifier, such as a driver license number, telephone number (including area code), or vehicle identification number (VIN). A relational database must always have one and only one primary key.
A primary key is a column -- or a group of columns -- in a table that uniquely identifies the rows of data in that table. For example, in the table below, CustomerNo, which displays the ID number assigned to different customers, is the primary key.
TableNameID for clarity
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