Guid vs Identity [英] Guid vs Identity

查看:45
本文介绍了Guid vs Identity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否有Select @@ identity的替代品可以返回只是

插入 GUID作为主键?


有没有人用Guid或Autonumber测试什么更快?

Hi,

Is there any replace for "Select @@identity" that could return "just
inserted" GUID as a primary key?

Has anyone tested what''s faster, working with Guid or Autonumber ?

推荐答案

Ilija_G(acMENT@on.net.mk)写道:
Ilija_G (ac****@on.net.mk) writes:
是否有任何替换Select @@ identity;可以返回只是插入 GUID作为主键?


最好的说法是:


DECLARE @guid uniqueidentifier

SELECT @guid = newid()

INSERT tbl(guidcol,...)

VALUES(@guid,...)


有谁测试了什么用Guid或Autonumber工作的速度更快?
Is there any replace for "Select @@identity" that could return "just
inserted" GUID as a primary key?
The best would be to say:

DECLARE @guid uniqueidentifier
SELECT @guid = newid()
INSERT tbl (guidcol, ...)
VALUES (@guid, ...)

Has anyone tested what''s faster, working with Guid or Autonumber ?




这是其中一个它取决于。我大多数情况下使用整数IDENTITY

列更好,因为它更小。当您检索数据时,这并不会支付
。由于IDENTITY值是连续的,因此

表示所有插入都在具有

键列的索引中发生,而使用guid时,它们遍布整个地方。

后者提供更多碎片,但热点更少。在任何情况下,IDENTITY列和guid上的
索引通常应该是非群集的。


我认为使用guids的平均原因是你的情况

这样的身份值根本无法使用,例如合并

复制。


-

Erland Sommarskog,SQL Server MVP, es****@sommarskog.se


SQL Server SP3联机丛书
http://www.microsoft.com/sql/techinf...2000/books.asp


>> Guid或Autonumber ..作为主键? <


你有没有考虑过不使用它们并找到真正的密钥?你在b $ b所做的就是使用PHYSICAL定位器,就像在文件系统中一样,

并破坏你的数据完整性。


我知道拥有魔法,通用,适合所有人的方式是非常好的。

可以解决每一个问题,但这总是错误的。设计数据库

是工作,需要研究和规划。
>> Guid or Autonumber .. as a primary key? <<

Did you ever consider not using either and find a REAL key? All you
are doing is using PHYSICAL locators, as you would in a file system,
and destroying your data integrity.

I know it is so nice to have "magic, universal, one-size-fits-all"
answer to every problem, but it is always wrong. Designing a databse
is work and it requires research and planning.


- CELKO--(jc ******* @ earthlink.net)写道:
--CELKO-- (jc*******@earthlink.net) writes:
Guid或Autonumber ..作为主键? <<
Guid or Autonumber .. as a primary key? <<



您有没有考虑过不使用它们并找到真正的密钥?所有你正在做的就是使用PHYSICAL定位器,就像你在文件系统中那样,并且破坏你的数据完整性。



Did you ever consider not using either and find a REAL key? All you
are doing is using PHYSICAL locators, as you would in a file system,
and destroying your data integrity.




切掉垃圾,Celko。你不知道Ilija

试图解决的业务问题。如果你不能帮助别人,只要保持你的大嘴

关闭。

-

Erland Sommarskog,SQL Server MVP,< a href =mailto:es **** @ sommarskog.se> es **** @ sommarskog.se


SQL Server SP3联机丛书
http://www.microsoft.com /sql/techinf...2000/books.asp


这篇关于Guid vs Identity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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