Id or [TableName]Id as primary key / entity identi

2019-05-07 00:04发布

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?

7条回答
贼婆χ
2楼-- · 2019-05-07 00:28

TableNameID for clarity

  1. Improve JOIN readability
  2. Clarity, say, when multiple FK "ID" columns (PK matches FK)
  3. ID is a reserved keyword
查看更多
登录 后发表回答