Id或[TableName] Id作为主键/实体标识符 [英] Id or [TableName]Id as primary key / entity identifier

查看:266
本文介绍了Id或[TableName] Id作为主键/实体标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首选使用Id作为主键的列名称或[TableName] Id作为命名约定?

Is it preferred to use "Id" as the column name for a primary key or "[TableName]Id" as a naming convention?


表:帐户

主键:Id

Table: Account
Primary Key: Id

- 对 -


表:帐户

主键:AccountId

Table: Account
Primary Key: AccountId


$ b $在我看到的实现中,似乎分解了大约50%/ 50%。每种方法有哪些优点和缺点?

It seems to be split about 50% / 50% in the implementations that I've seen. What are the advantages and disadvantages in each approach?

后续行动:

使用一个约定是有意义的我的数据库,另一个在我的实体代码中?还是应该保持一致?

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?

推荐答案

TableNameID为了清楚起见

TableNameID for clarity


  1. 提高JOIN的可读性

  2. 说清楚,多个FKID列(PK匹配FK)

  3. ID是保留关键字

这篇关于Id或[TableName] Id作为主键/实体标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆