对标识列使用 uniqueidentifier(GUID) 还是 bigint 更好? [英] Is it better to use an uniqueidentifier(GUID) or a bigint for an identity column?

查看:25
本文介绍了对标识列使用 uniqueidentifier(GUID) 还是 bigint 更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 SQL 服务器,对标识列使用 uniqueidentifier(GUID) 还是 bigint 更好?

For SQL server is it better to use an uniqueidentifier(GUID) or a bigint for an identity column?

推荐答案

这取决于你在做什么:

  • 如果速度是主要问题,那么一个普通的 int 可能就足够了.
  • 如果您真的有超过 20 亿条记录(带有 B ;) ),那么使用 bigint 或顺序 guid.
  • 如果您需要能够轻松地与远程创建的记录同步,那么 Guid 真的很棒.
  • If speed is the primary concern then a plain old int is probably big enough.
  • If you really will have more than 2 billion (with a B ;) ) records, then use bigint or a sequential guid.
  • If you need to be able to easily synchronize with records created remotely, then Guid is really great.

更新
关于 Guids 的一些其他(不太明显的)注释:

Update
Some additional (less-obvious) notes on Guids:

  • 它们可能对索引很困难,这会削弱数据库性能的核心
  • 您可以使用顺序 guid 来恢复一些索引性能,但放弃第二点中使用的一些随机性.
  • Guid 可能很难手动调试(where id='xxx-xxx-xxxxx'),但您也可以通过顺序 guid 获得其中的一些(where id='xxx-xxx' + '123').
  • 出于同样的原因,Guids 可以使基于 ID 的安全攻击更加困难 - 但并非不可能.(您不能只输入 'http://example.com?userid=xxxx' 并期望获得其他人帐户的结果).
  • They can be hard on indexes, and that cuts to the core of database performance
  • You can use sequential guids to get back some of the indexing performance, but give up some of the randomness used in point two.
  • Guids can be hard to debug by hand (where id='xxx-xxx-xxxxx'), but you get some of that back via sequential guids as well (where id='xxx-xxx' + '123').
  • For the same reason, Guids can make ID-based security attacks more difficult- but not impossible. (You can't just type 'http://example.com?userid=xxxx' and expect to get a result for someone else's account).

这篇关于对标识列使用 uniqueidentifier(GUID) 还是 bigint 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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