数据库设计+表 ID
我经常听说,数值递增的数字对于静态数据表来说是很好的 ID。这对我来说从来没有多大意义 - 我宁愿有有意义的 id。
举个例子:假设我在表中维护CurrencyInfo。对于 USD,行标识符应该是 1 还是 USD?首选做法是什么?为什么?
请让我知道你的想法。
I have often heard that numerically increasing numbers make good ids for static data tables. This has never made much sense to me - I would rather have meaningful ids.
To give you an example: say I am maintaining CurrencyInfo in a table. For USD, should the row identifier be 1 or USD? What is the preferred practice and why?
Do please let me know your thoughts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在谈论的 id 称为
代理键
。您可以在此处阅读更多相关信息。要了解它们相对于
业务密钥
的优点/缺点,请查看这里。您还可以查看此答案。
The id that you are talking about is known as
surrogate key
. You can read more about it here.To know their advantages/disadvantages over
business keys
, take a look here.You can also take a look at this answer.
唯一标识符不应该是有意义的,它应该是唯一标识符:) 如果您的 ID 现在有意义,并不意味着它以后也有意义。这些事情总是可以改变的。
所以恕我直言,你应该坚持使用 DBMS 支持的唯一标识符。这些可以优化等等。
The unique identifier should NOT be something meaningful, it should be a unique identifier :) If your ID is meaningful NOW, it doesn't mean that it's meaningful later. Those things can always change..
So IMHO you should stick to a DBMS supported unique identifier. Those can be optimized etc..