views:

195

answers:

5

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  A: 

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 defualt value:

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

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

Kronass
A: 

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())
Cade Roux
A: 

It's a uniqueidentifier column

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

gbn
A: 

Thanks everyone. It generate automatically in management studio

amby
Please accept one of the answers then...
gbn
NEWID may be the right answer but in management studion i just select its rowguid property to true and when i enter data to other fields except this, management studio itself enter the string like u mention above: 6F9619FF-8B86-D011-B42D-00C04FC964FF. so i came to know that i dont have to enter values in this field, it will be automatically generated by management studio when selecting column as rowguid
amby