开发者

how to enter values in rowguid column?

开发者 https://www.devze.com 2022-12-27 03:31 出处:网络
can a开发者_开发问答nyone please tell me the right way to insert values in the rowguid column of the table? I m using sql server management studiouse the NEWID() function to generate one:

can a开发者_开发问答nyone please tell me the right way to insert values in the rowguid column of the table? I m using sql server management studio


use the NEWID() function to generate one:

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

or you can set it as a default value:

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


You can Set NEWSEQUENTIALID() as Default in table

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

Read more about it here

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


It's a uniqueidentifier column

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


I was able to insert by using the following:

Insert Into Table FOO(Col1, Col2, RowGuidCol)

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

It is very important to follow to place the dashes in the correct place. You do not need to have the 0x in the beginning of the string. FYI-Updates are not allow on columns whith the rowguid col property set. I hope this helps.


Assuming that you have a uniqueidentifier column rg in your table t which is set to be the rowguid:

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

or

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号