dbTalk Databases Forums  

Value of column withNEWID() default

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Value of column withNEWID() default in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Simon Wadsworth
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.