I’m just curious, I’ve always wondered why this is so.
In an attempt to find out if I could create one without the character 4 at the 15th character, I ran this…
DECLARE @GUID AS NVARCHAR(36)
DECLARE @COUNT AS INTEGER
SET @COUNT = 0
SET @GUID = CAST(NEWID() AS NVARCHAR(36))
WHILE SUBSTRING(@GUID,15,1) = '4'
BEGIN
SET @COUNT = @COUNT + 1
SET @GUID = CAST(NEWID() AS NVARCHAR(36))
END
PRINT 'Attempts : ' + CAST(@COUNT AS NVARCHAR(MAX))
PRINT @GUID
As you might guess, this never actually ended for me. I had this running on a server all weekend.
If NewID is supposed to always give a random ID, why is that 4 always there.
BC13DF1C-60FB-41C2-B5B2-8F1A73CF2485
D790D359-AB3D-4657-A864-FA89FACB3E99
DF1BBC0C-4205-48E8-A1B6-EA9544D7C6E5
Is the 15th position some kind of identify as to the system that generated the uniqueidentifier?
In fact, the same thing happens with VB.net’s System.Guid.Newguid function. Is the 4 a Microsoft only thing?
Edit: Perhaps I should have also asked, are they actually unique? Can one rely one them being unique in an entire database? I know database systems based on the assumption these are guaranteed to be unique within the database. With several millions records in different tables… are any of them potentially the same?
The 4 indicates that it was generated using a pseudo-random number; See Wikipedia’s article for Globally Unique Identifiers under Algorithm.