你喜欢你的主键? [英] How do you like your primary keys?
问题描述
在我的团队相当热烈的讨论我是为了想大多数人都喜欢作为主键。我们有以下组 -
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-
- 在内部/ BigInt有哪些自动增量是好足够的主键。
- 应该有至少3列构成主键。
- 标识,GUID和人类可读的行标识符都应该区别对待。
请告诉我对的PK最好的方法?这将是真棒,如果你能证明你的意见。有没有更好的办法是,以上?
Whats the best approach for PKs? It would be awesome if you could justify your opinion. Is there a better approach that the above?
编辑:任何人有一个简单的示例/算法生成人类可读的标识符行的扩展以及
Anyone has a simple sample/algorithm to generate human readable identifiers for rows that scales well?
推荐答案
如果你打算做与偶尔连接的应用程序的数据库之间的同步,那么你应该使用的GUID为您的主键。它是一种用于调试的痛苦,因此除了这种情况下,我倾向于坚持到整数的自动增量。
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.
这篇关于你喜欢你的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!