你如何喜欢你的主键? [英] How do you like your primary keys?

查看:115
本文介绍了你如何喜欢你的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的团队的一个相当动画的讨论中,我被认为是大多数人喜欢的主要关键。我们有以下组 -


  1. Int / BigInt哪个自动增量是足够好的主键。

  2. 应该有至少3列组成主键。

  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-

  1. Int/ BigInt which autoincrement are good enough primary keys.
  2. There should be at least 3 columns that make up the primary key.
  3. 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.

这篇关于你如何喜欢你的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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