patternsqlMinor
Is NEWSEQUENTIALID unique within a database for Many tables?
Viewed 0 times
uniquenewsequentialidtableswithindatabaseformany
Problem
Is NEWSEQUENTIALID unique within a database? We plan many tables in a database with NEWSEQUENTIALID, inserting simultaneously and want to ensure every guid will be unique, regardless if they are in different tables.
Regular NEWID() will guarantee uniqueness in a database, and chances of having duplicate is chance of being struck by asteroid/lightning, however they do not alleviate the fragmentation issue.
This article talks about Mac address, however I want to specify question for database specific above.
https://stackoverflow.com/questions/28404964/is-uniqueidentifier-unique-across-databases
Regular NEWID() will guarantee uniqueness in a database, and chances of having duplicate is chance of being struck by asteroid/lightning, however they do not alleviate the fragmentation issue.
This article talks about Mac address, however I want to specify question for database specific above.
https://stackoverflow.com/questions/28404964/is-uniqueidentifier-unique-across-databases
Solution
According to Microsoft Docs the value is unique on a per computer basis, and also on multiple computers as long as the computer in question has a network card (assumedly the generation algorithm uses some values taken from the network card to generate the GUID)
Each GUID generated by using NEWSEQUENTIALID is unique on that computer. GUIDs generated by using NEWSEQUENTIALID are unique across multiple computers only if the source computer has a network card.
Other than this though, there do seem to be some caveats around that uniqueness:
The UuidCreateSequential function has hardware dependencies. On SQL Server, clusters of sequential values can develop when databases (such as contained databases) are moved to other computers. When using Always On and on SQL Database, clusters of sequential values can develop if the database fails over to a different computer.
And on the page for UuidCreateSequential we can also see that the function is guaranteed to be unique across computers if the network card is present
Computers with ethernet/token ring addresses generate UUIDs that are guaranteed to be globally unique.
Each GUID generated by using NEWSEQUENTIALID is unique on that computer. GUIDs generated by using NEWSEQUENTIALID are unique across multiple computers only if the source computer has a network card.
Other than this though, there do seem to be some caveats around that uniqueness:
The UuidCreateSequential function has hardware dependencies. On SQL Server, clusters of sequential values can develop when databases (such as contained databases) are moved to other computers. When using Always On and on SQL Database, clusters of sequential values can develop if the database fails over to a different computer.
And on the page for UuidCreateSequential we can also see that the function is guaranteed to be unique across computers if the network card is present
Computers with ethernet/token ring addresses generate UUIDs that are guaranteed to be globally unique.
Context
StackExchange Database Administrators Q#224783, answer score: 5
Revisions (0)
No revisions yet.