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

StackOverflow https://stackoverflow.com/questions/17881897

  •  04-06-2022
  •  | 
  •  

Question

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

Was it helpful?

Solution 2

A simple LINQPad mockup answers your question:

var dictionary = new Dictionary<int, Guid>();

for (int i = 0; i < 5; i++)
    dictionary.Add(i, Guid.NewGuid());

dictionary.OrderBy(d => d.Value);

Results in:

Key Value 
2   3624183d-581a-45bc-9d3d-cafeddaf8585 
0   4b4685c9-f163-4694-ae8c-4b83402a293c 
4   7a14d8e4-d870-4f33-bfb3-f4337b756e18 
1   b93131c7-c0d7-42b4-82b5-e3cc456214a9 
3   cfdc0bc8-7f5a-4601-a927-a759bb9e33c6 

OTHER TIPS

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

Please see this

A Globally Unique Identifier (GUID, /ˈɡwɪd/or /ˈɡuːɪd/) is a unique reference number used as an identifier in computer software. The term GUID typically refers to various implementations of the universally unique identifier (UUID) standard.1 GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, such as {21EC2020-3AEA-1069-A2DD-08002B30309D}. GUIDs generated from random numbers contain 6 fixed bits saying they are random and 122 random bits; the total number of unique such GUIDs is 2122 or 5.3×1036. This number is so large that the probability of the same number being generated randomly twice is negligible; however other GUID versions have different uniqueness properties and probabilities, ranging from guaranteed uniqueness to likely non-uniqueness.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top