Reputation:
I would like to have a column in one of my tables set to a GUID value. Can someone tell me how I can do this by default and also what datatype and size I should use for this. Is there a special guid datatype or should I use a char or varchar?
Upvotes: 0
Views: 1755
Reputation: 411
GUID are the UNIQUEIDENTIFIER data type, example below of a table with one
CREATE TABLE MyUniqueTable
(UniqueColumn UNIQUEIDENTIFIER DEFAULT NEWID(),
Characters VARCHAR(10) )
GO
You use NEWID() and SQL will generate a new guid for you.
Upvotes: 1