How to enter values ​​in rowguid column?

can someone tell me the correct way to insert values ​​into the rowguid column of a table? I am using sql server management studio

+4
source share
5 answers

use the NEWID() function to create it:

 CREATE TABLE myTable(GuidCol uniqueidentifier ,NumCol int) INSERT INTO myTable Values(NEWID(), 4) SELECT * FROM myTable 

or you can set it as the default value:

 CREATE TABLE myTable(GuidCol uniqueidentifier DEFAULT NEWSEQUENTIALID() ,NumCol int) INSERT INTO myTable (NumCol) Values(4) SELECT * FROM myTable 
+4
source

You can set NEWSEQUENTIALID () as the default value in the table

 CREATE TABLE GuidTable ( ID UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID() PRIMARY KEY, TEST INT ) 

Read more about this here

http://msdn.microsoft.com/en-us/library/ms189786.aspx

+3
source

This is the uniqueidentifier column

You can send a value like "6F9619FF-8B86-D011-B42D-00C04FC964FF" or use the NEWID / NEWSEQUENTIALID functions to generate one

+2
source

I managed to insert using the following:

Insert into table FOO (Col1, Col2, RowGuidCol)

Values ​​(5, 'Hello,' 1A49243F-1B57-5848-AA62-E4704544BB34 ')

It is very important to monitor the placement of the dash in the right place. You do not need to have 0x at the beginning of the line. FYI-Updates are not allowed for columns with the specified rowguid col property value. Hope this helps.

+1
source

Assuming you have a uniqueidentifier rg column in your table t that is given as rowguid:

 INSERT INTO TABLE t (rg) VALUES (NEWID()) 

or

 INSERT INTO TABLE t (rg) VALUES (NEWSEQUENTIALID()) 
0
source

Source: https://habr.com/ru/post/1306732/


All Articles