Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are GUIDs timely ordered ? If ORDER BY used with a GUID variable type, will records created lately come late?

Tags:

c#

sql

guid

Are GUIDs timely ordered ? I mean if you use ORDER BY with a GUID variable type, will records created lately come late ?

like image 374
Ehsan88 Avatar asked Jul 26 '13 12:07

Ehsan88


People also ask

Are GUIDs ordered?

Lexically they're unordered, but that doesn't mean with a different comparer that they are not in fact ordered. However @wudzik provides the meaningful answer that the guids are generated by cryptographic number generation and not with any time series component to create any type of implicit order.

How are GUIDs generated?

Individuals and organizations can create GUIDs using a free GUID generator that is available online. An online generator constructs a unique GUID according to RFC 4122. When creating a GUID, users should note the timestamp, clock sequence and the node ID -- such as a Media Access Control (MAC) address.

How does SQL Server sort GUIDs?

NET languages, Guid values have a different default sort order than in SQL Server. If you find the need to order an array or list of Guid using SQL Server comparison semantics, you can use an array or list of SqlGuid instead, which implements IComparable in a way which is consistent with SQL Server semantics.

Which data type is used for assigning GUID value revisit choose the best option o Unique O Uniqueidentyfier o GUID?

GUID is a 16 byte binary SQL Server data type that is globally unique across tables, databases, and servers. The term GUID stands for Globally Unique Identifier and it is used interchangeably with UNIQUEIDENTIFIER. Execute the above line of SQL multiple times and you will see a different value every time.


1 Answers

On Windows, GUIDs (UUIDs) are created from a cryptographic random number generator with UuidCreate. They are version 4 UUIDs in terms of RFC 4122. No timestamps or ethernet cards are involved, unless you're using old school version 1 GUIDs created with UuidCreateSequential.

See also How Random is System.Guid.NewGuid()? (Take two)

source: https://stackoverflow.com/a/3011149/1714342

like image 165
Kamil Budziewski Avatar answered Oct 03 '22 18:10

Kamil Budziewski