Microsoft SQL Server 2005
Database Design Best Practices

How to use the NewSequentialID function?

 

Execute the following script in Query Editor to demonstrate the use of newsequentialid() function as opposed to the newid() function:

USE tempdb
GO
CREATE TABLE RandomOld (UniqueID uniqueidentifier DEFAULT NewID())
CREATE TABLE RandomSequentialNew (UniqueID uniqueidentifier DEFAULT NewSequentialID())
CREATE TABLE RandomSequentialNew1 (UniqueID uniqueidentifier DEFAULT NewSequentialID())

INSERT INTO RandomOld DEFAULT VALUES
INSERT INTO RandomOld DEFAULT VALUES
INSERT INTO RandomOld DEFAULT VALUES
INSERT INTO RandomOld DEFAULT VALUES

INSERT INTO RandomSequentialNew DEFAULT VALUES
INSERT INTO RandomSequentialNew DEFAULT VALUES
INSERT INTO RandomSequentialNew DEFAULT VALUES
INSERT INTO RandomSequentialNew DEFAULT VALUES

INSERT INTO RandomSequentialNew1 DEFAULT VALUES
INSERT INTO RandomSequentialNew1 DEFAULT VALUES
INSERT INTO RandomSequentialNew1 DEFAULT VALUES
INSERT INTO RandomSequentialNew1 DEFAULT VALUES

SELECT UniqueID, BinaryValue=CONVERT(binary(16), UniqueID)
FROM RandomOld
SELECT UniqueID, BinaryValue=CONVERT(binary(16), UniqueID)
FROM RandomSequentialNew
SELECT UniqueID, BinaryValue=CONVERT(binary(16), UniqueID)
FROM RandomSequentialNew1

GO
DROP TABLE RandomOld
GO
DROP TABLE RandomSequentialNew
GO
DROP TABLE RandomSequentialNew1
GO

 

The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page