views:

25

answers:

1

Hi,
i have a simple table "MyTable" with single colum "id" which type is uniqueidetifier and rowguid is set to true. I insert new values like this

INSERT INTO MyTable
DEFAULT VALUES

how to get inserted by server guid ?
Best Regards,
Iordan

+4  A: 

Assuming you are on at least SQL Server 2005 use the OUTPUT clause.

DECLARE @MyTable TABLE 
(
id UNIQUEIDENTIFIER DEFAULT NEWID()
)

INSERT INTO @MyTable
OUTPUT inserted.id
DEFAULT VALUES
Martin Smith