how to enter values in rowguid column?

末鹿安然 提交于 2020-01-03 13:36:07

问题


can anyone please tell me the right way to insert values in the rowguid column of the table? I m using sql server management studio


回答1:


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



回答2:


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




回答3:


It's a uniqueidentifier column

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




回答4:


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.




回答5:


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())


来源:https://stackoverflow.com/questions/2624681/how-to-enter-values-in-rowguid-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!