Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

I have used NewID() in SQL which give me the Unique ID.
But I want to know on what bases it is generated.

Eg: SELECT NEWID()
Posted

A Guid is 32 hex digits grouped into chunks of 8-4-4-4-12. Number of unique Guids is 2^128. Thats a lot..
Guids are created in different ways. The most used Guid is a version 4 Guid based on Time, MAC-address and Random data. (the first number of 3rd chunk is the version number)
            version
              |     
542DF77C-B284-4623-9BC8-FD1E9343CD2C
1A32EAFB-28DD-4E4A-AD27-58B9DD301CD9
87FD5B4E-E733-4B18-951E-F6EBC8960D22
DCE7501C-D419-424A-8C5B-FBE2589AFB73
B056348F-3E4A-4739-87A9-7872FB083295


Since it's using both Mac-address and Time, the only way to create a duplicate Guid is to adjust them clock on your server back in time and try to regenerate a duplicate. You'll never manage to create duplicates, but i theory you can.
 
Share this answer
 
v3
Comments
Arunprasath Natarajan 16-Aug-12 0:29am    
Tan Q
NewID generates a Globally Unique IDentifier, or GUID. This is a 128 bit number which means that there is less chance of getting a duplicate value that there is of you winning the lottery.

This week.

And next week.

And every single week from now to the end of your life.

The generated value is not truly unique, but the odds are so high that they can be treated as unique values for all practical purposes.
 
Share this answer
 
Comments
Arunprasath Natarajan 15-Aug-12 7:51am    
Tan q, Can you give me the logic of its generation...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900