HI @Stephen Liang ,
Welcome to Microsoft Q&A!
A column or local variable of uniqueidentifier data type can be initialized to a value in the following ways:
- By using the NEWID or NEWSEQUENTIALID functions.
- By converting from a string constant in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, in which each x is a hexadecimal digit in the range 0-9 or a-f. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid uniqueidentifier value.
Please refer below example:
DECLARE @id uniqueidentifier
SET @id = NEWID()
insert into Archive.dbo.Records (Id,Ref1,Ref2,Name1,Date1) values
(@id,'a','b','c',GETDATE())
select * from Archive.dbo.Records
Output:
Id Ref1 Ref2 Name1 Date1 Currency Amount Memo1 Memo2 Chart
6845E57D-68DA-4544-9FFB-D2EF56562096 a b c 2021-02-18 NULL NULL NULL NULL NULL
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.