你觉得你的主键怎么样? [英] How do you like your primary keys?

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

问题描述

在我的团队进行了一次相当活跃的讨论中,我想到了大多数人喜欢什么作为主键.我们有以下几组-

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 自动增量是足够好的主键.
  2. 应该至少有 3 列组成主键.
  3. Id、GUID 和人类可读的行标识符都应该区别对待.

PK 的最佳方法是什么?如果你能证明你的观点,那就太棒了.有没有比上面更好的方法?

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?

任何人都有一个简单的示例/算法来为缩放良好的行生成人类可读的标识符?

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屋!

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