Comments (4)
from p3c.
谢谢回答,但是我所说的业务id,其实也是无意义的id,是数据库自增的,更多的只是想表达id字段的取名而已,取比较有意义的名字,会方便操作。
from p3c.
个人观点是, 通常情况下, 不要对 属性进行 重复表意
比如:
user {
id
name
age
}
但这并不意味着任何地方都不需要这个所谓的 "前缀", 比如:
app {
id
user_id
}
其中 id
自然是 app.id
, user_id
自然是代表了一个 user.id
但这并不是一个好例子, 再进一步讲, user_id
也非常不恰当
回过头来看, bug_id
user_id
真的就是 "业务id" 吗? 顶多能体现这个字段的 "类型" 罢了
其中, user_id
创建人?负责人?还是开发者?
不如改成更明确的 owner_id
app {
id
owner_id
}
会更加合适,
from p3c.
当使用有意义的something_id,对于pk和fk关联确实更方便,但java开发手册中有个强制规定:
【强制】 不得使用外键与级联, 一切外键概念必须在应用层解决。
所以pk和fk的关联优势没有了,所以手册主键是id,如果没有该强制规定,id和something_id都可以,都有自己的优缺点。
Naming primary keys "id" vs "something_id" in SQL
from p3c.
Related Issues (20)
- 建议增加diff模块或者发布历史 HOT 2
- 2023.1版本插件报错 HOT 15
- [Doc] The README file is not clear and some format was incorrect
- 执行./gradlew runIde,idea报错rule set java/ali-pmd not found 问题 如何解决?
- 乱码问题 HOT 1
- idea2020.1.1安装好插件使用时右下角报IDE Fatal Errors错误导致无法使用 HOT 1
- try-with-resources 的注意点
- 数组下标越界 HOT 1
- 提几条日常编码时的想法供参考
- 2023.2版本插件报错 HOT 13
- 有没有web的开发手册开发规范
- 规约中有关前后端接口日期时间传递的约定是在挖大坑 HOT 8
- URL Broker 指的是什么
- beta版本试用,增加了对Record类的检测,优化了Switch中default块的判断 HOT 2
- How to add a new rule HOT 69
- stream和enum的格式化能不能优化下
- idea 2023.1.5版本安装规约插件代码规约失效 HOT 1
- How can I use my custom rule which is similar to defined rule? HOT 1
- LockShouldWithTryFinallyRule规则不生效
- 请问下这个插件是没更新了吗? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p3c.