ROWGUIDCOL
Example
Section titled “Example”CREATE TABLE Test_GUID( ID uniqueidentifier NOT NULL ROWGUIDCOL, Name varchar(50))
-- Insert two rowsINSERT INTO Test_GUID (ID, Name)VALUES (NEWID(), 'Test 1'), (NEWID(), 'Test 2')
-- Display rowsSELECT * FROM Test_GUIDOutput
Section titled “Output”| ID | Name || ------------------------------------ | ----- || 6F9619FF-8B86-D011-B42D-00C04FC964FF | Test 1|| 6F9619FF-8B86-D011-B42D-00C04FC964DE | Test 2|Explanation
Section titled “Explanation”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.