Skip to content

ROWGUIDCOL

CREATE TABLE Test_GUID
(
ID uniqueidentifier NOT NULL ROWGUIDCOL,
Name varchar(50)
)
-- Insert two rows
INSERT INTO Test_GUID (ID, Name)
VALUES (NEWID(), 'Test 1'), (NEWID(), 'Test 2')
-- Display rows
SELECT * FROM Test_GUID
| ID | Name |
| ------------------------------------ | ----- |
| 6F9619FF-8B86-D011-B42D-00C04FC964FF | Test 1|
| 6F9619FF-8B86-D011-B42D-00C04FC964DE | Test 2|

In this example, a column ‘ID’ is defined as a uniqueidentifier and assigned the property ROWGUIDCOL. This makes the ‘ID’ column a row globally unique identifier column which will store a unique value for each row, generated by the NEWID() function. Two rows are inserted into the table with uniqueidentifier values generated by the NEWID() function for each row, and finally the rows of the table are displayed. The ROWGUIDCOL property is used to specify the unique row identifier column in a table which is primarily used with replication.