问题描述
说我有这个向导:
{2A87E3E2-2B6A-4149-9F5A-1B76092843D9}
{2A87E3E2-2B6A-4149-9F5A-1B76092843D9}
它实际上是否将一个字母数字存储在数据库中? (我不认为是因为它必须容纳16个字节.)
Does it actually store this an an alpha numeric in the database? (I don't think so cause it has to fit in 16 bytes.)
如果没有,那么如何存储? (我的猜测是一个十六进制数字,但我不确定.)
If it does not, then how is it stored? (My guess is as a hex number, but I am not sure.)
如何判断一个GUID是否大于另一个GUID? (出于建立索引的目的可能需要知道的内容.)您是否刚刚阅读GUID像一个十六进制数字(供比较)?
How can you tell if one GUID is greater than another? (Which you may need to know for indexing purposes.) Do you read the GUID just like a hex number (for comparison)?
推荐答案
GUID在内部存储为binary(16). MSDN上的使用uniqueidentifier数据" 告诉您这一点.{
}
和-
不是值的一部分.
A GUID is stored as binary(16) internally. "Using uniqueidentifier Data" on MSDN tells you this.The {
}
and -
are not part of the value.
GUID可以排序",并且具有更大/更少的比较:请参见规范的.sorted-by-sql-server.aspx"rel =" noreferrer>如何通过SQL Server对GUID进行排序?".
GUIDs can be "sorted" and have greater/lesser comparisons: see the canonical "How are GUIDs sorted by SQL Server?".
注意:这意味着它们不要按二进制(16)排序(除非您认为我是CAST,否则...)
Note: this means they don't sort as binary(16) (unless you CAST I suppose...)
我看不到为什么,您在现实生活中会希望这样做(不是索引,我的意思是现实世界):关于NEWID的排序"潜力的唯一用途是用于随机ORDER BY NEWID()
I can't see why you'd want this in real life (not indexing, I mean real world): about the only use for the "sorting" potential of NEWID is for the random rows tricks of ORDER BY NEWID()
您可以使用带有 NEWSEQUENTIALID的升序" GUID(基于以上文章) .但是,在Windows重新启动=无意义的IMO之后,这种排序"不会继续.
You can have "ascending" GUIDs (based on the article above) with NEWSEQUENTIALID. However, this "sorting" doesn't continue after a Windows restart = pointless IMO.
这篇关于guid如何在SQL Server中实际存储和排序/比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!