Skip to content
Advertisement

Set some default guid value in uniqueidentifier in sql

I need to set default guid value, not NEWID() in uniqueidentifier column in SQL.

For example: Have a column TestID in TestTable, need to set default TestID to "DA74F684-B228-48D5-9692-69465BE6D720".

Thank you in advance.

Advertisement

Answer

Here’s your script.

ALTER TABLE TestTable drop COLUMN TestID 

ALTER TABLE TestTable ADD TestID uniqueidentifier DEFAULT cast('DA74F684-B228-48D5-9692-69465BE6D720' as uniqueidentifier);

then, update exsting records

UPDATE TestTable  set TestID = 'DA74F684-B228-48D5-9692-69465BE6D720'
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement