|
Execute the following Microsoft SQL Server Transact-SQL (T-SQL) script in Management Studio (SSMS) Query Editor, SQLCMD or other client software
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
|