Value of column withNEWID() default -
11-16-2004
, 07:43 AM
When using the NEWID() function as a DEFAULT for a UNIQUEIDENTIFIER
column is it possible to retrieve the NEWID() value after an INSERT?
e.g.
CREATE TABLE Test
(
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
v1 INT,
v2 INT
)
... followed by ..
INSERT INTO Test (v1, v2) VALUES (1, 2)
... at which point I'd like to get the value inserted for 'id'.
It would be useful to have something like @@LASTNEWID, which would
operate like @@IDENTITY, so the value could be returned to the client
and used within the same scope to create dependent child rows.
Obviously this would require some restrictions, such as only returning
the last one generated if a table has more than one column with
NEWID() as the default, but I imagine this would be more useful than
not having the feature.
Many Thanks
Simon Wadsworth |