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

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.

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