Using the newsequentialid() GUID Function
In SQL Server 2005, you can use a new GUID function called newsequentialid() to populate your uniqueidentifer column.
Kimberly L. Tripp
January 23, 2007
1 Min Read
![Using the newsequentialid() GUID Function Using the newsequentialid() GUID Function](https://eu-images.contentstack.com/v3/assets/blt07f68461ccd75245/blt7e0c250e8962be51/6627743e42e8634b588af759/guy-red-eye_0_0.jpg?width=1280&auto=webp&quality=95&format=jpg&disable=upscale)
In SQL Server 2000, the only SQL Server function for GUIDs is newid, but this function doesn't create an ever-increasing pattern. In SQL Server 2005, you can use a new GUID function called newsequentialid() to populate your uniqueidentifier column. Here's an example of how you can use it:
CREATE TABLE Test ( TestID uniqueidentifier CONSTRAINT Test_TestID_Default DEFAULT newsequentialid(),Inserted datetime CONSTRAINT Test_Inserted_Default DEFAULT getdate()) go INSERT Test DEFAULT VALUESgo SELECT * FROM Testgo
Is there a way to create a sequential GUID in SQL Server 2000? Yes—you can use an extended procedure to generate sequential GUIDs or you can leverage someone else's code. Gert Drapers wrote an extended stored procedure, which he has published on his Web site, SQLDev.NET, at http://sqldev.net/xp/xpguid.htm.
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like