Simon's SQL

SQL,DBA,tuning,Trouble Shooting,Performance

Posts Tagged ‘NewID’

uniqueidentifier : GUID in SQL

Posted by Simon Cho on 01/02/2013

1. newsequentialid()

This is one of the function to generate sequence GUID to reduce fragmentation.

But, it’s not grantee uniqueness.
It’s wrapped by windows function UuidCreateSequential,

Creates a GUID that is greater than any GUID previously generated by this function on a specified computer since Windows was started.
After restarting Windows, the GUID can start again from a lower range, but is still globally unique.
When a GUID column is used as a row identifier, using NEWSEQUENTIALID can be faster than using the NEWID function.
This is because the NEWID function causes random activity and uses fewer cached data pages. Using NEWSEQUENTIALID also helps to completely fill the data and index pages.

2. uniqueidentifier sorting.

3. uniqueidentifier converting

SELECT CONVERT(uniqueidentifier, 0x000102030405060708090A0B0C0D0E0F)
SELECT CONVERT(uniqueidentifier, 0x00000000000000000123456789ABCDEF)
SELECT CONVERT(uniqueidentifier, 0x000000000123456789ABCDEF00000000)
SELECT CONVERT(UNIQUEIDENTIFIER, '00000000-0123-4567-89AB-CDEF00000000')

Posted in Common | Tagged: , , | Leave a Comment »