Use of NEWSEQUENTIALID() to Generate GUID
NEWSEQUENTIALID() produces a GUID that is larger than any GUID the method has previously produced on that computing device. In some conditions, this mechanism is useful for the reduction of fragmentation.
Let’s create a table with GUID column:
The name of the table is Product3, and the query for it is shown below:
Create table
CREATE TABLE Product3 (
ID uniqueidentifier PRIMARY KEY DEFAULT NEWSEQUENTIALID(),
ProductName varchar(255)
);
--Insert records
INSERT INTO Product3 (ProductName) VALUES ('Oreo');
INSERT INTO Product3 (ProductName) VALUES ('RENEE');
Output:
What is a GUID in SQL Server?
Globally Unique Identifiers, or GUIDs, are 16-byte (128-bit) binary data types in SQL Server that contain values and are represented by unique identifiers. Each table modeling procedure starts with a business key, surrogate key, identity key, etc. An increasingly distinct identity is required when common business entities need to be joined for data storage and analytics.
GUIDs are utilized in these situations since they are distinct for all servers, databases, and tables. Furthermore, when compared to other data formats, GUIDs might be somewhat large.