问题描述
在我的团队的一个相当动画的讨论中,我被认为是大多数人喜欢的主要关键。我们有以下组 -- Int / BigInt哪个自动增量是足够好的主键。
- 应该有至少3列组成主键。
- ID,GUID和人类可读行标识符都应该被不同的对待。
PK的最佳方法是什么?如果你能证明你的意见,那将是非常棒的上面有更好的做法吗?
编辑:任何人都有一个简单的样本/算法来生成可以扩展的行的人类可读标识符
如果要在偶尔连接的应用程序之间的数据库之间进行任何同步,那么您应该使用GUID作为主键。这是一个调试的痛苦,除了这种情况,我倾向于坚持自动增量的ints。
自动增量int应该是你的默认值,而不是使用它们应该是合理的。
In a fairly animated discussion in my team I was made to think what most people like as primary keys. We had the following groups-
- Int/ BigInt which autoincrement are good enough primary keys.
- There should be at least 3 columns that make up the primary key.
- Id, GUID and human readable row identifiers all should be treated differently.
What's the best approach for PKs? It would be awesome if you could justify your opinion. Is there a better approach that the above?
EDIT: Anyone has a simple sample/algorithm to generate human readable identifiers for rows that scales well?
If you're going to be doing any syncing between databases with occasionally connected apps, then you should be using GUIDs for your primary keys. It is kind of a pain for debugging, so apart from that case I tend to stick to ints that autoincrement.
Autoincrement ints should be your default, and not using them should be justified.
这篇关于你如何喜欢你的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!