Using Sql Server 2008: I want to insert a specific value (for example: 3513CB65-7FF4-477D-B518-E7FF7B298CB) to a uniqueidentifier field of a table.
How can to declare the value and how to insert it?
You can use NEWID() function of TSQL as;
DECLARE @myUid uniqueidentifier
SET @myUid = NEWID()
INSERT INTO [MYTABLE] (UNIQUEIDENTIFIER_FIELD, SOME_OTHER_FIELD)
VALUES (@myUid, 'some other field data')
Or you could even use NEWID() directly in INSERT statement as:
INSERT INTO [MYTABLE] (UNIQUEIDENTIFIER_FIELD, SOME_OTHER_FIELD)
VALUES (NEWID(), 'some other field data')
Edit: For hardcoded value, you need to use single quotes (') as;
INSERT INTO [MYTABLE] (UNIQUEIDENTIFIER_FIELD, SOME_OTHER_FIELD)
VALUES ('3513CB65-7FF4-477D-B518-E7FF7B298CB2', 'some other field data')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With