Wednesday 14 November 2012

Define a column as guid as type

A quick tips to define a column as a guid

create table DevenvaGuidTips (
guid uniqueidentifier PRIMARY KEY DEFAULT NEWSEQUENTIALID() ROWGUIDCOL
,.....



MSDN :
Unlike columns defined with the IDENTITY property, the Database Engine does not automatically generate values for a column of type uniqueidentifier. To insert a globally unique value, create a DEFAULT definition on the column that uses the NEWID or NEWSEQUENTIALID function to generate a globally unique value