user3568783
user3568783

Reputation:

How can I set a column value to a GUID and what data type should I use?

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

Answers (1)

swestfall
swestfall

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

Related Questions