sql - Return NEWSEQUENTIALID() as an output parameter -


imagine table looks this:

create table [dbo].[test](      [id] [uniqueidentifier] null,      [name] [varchar](50) null )  go  alter table [dbo].[test] add  constraint [df_test_id]  default (newsequentialid()) [id] go 

with insert stored procedure looks this:

create procedure [insert_test]     @name varchar(50),     @id uniqueidentifier output begin     insert test(         name     )     values(         @name     ) end 

what best way guid inserted , return output parameter?

use output clause of insert statement.

create procedure [insert_test]     @name varchar(50),     @id uniqueidentifier output begin     declare @returnid table (id uniqueidentifier)      insert test(         name     )     output inserted.id @returnid     values(         @name     )      select @id = r.id @returnid r end go  /* test procedure */ declare @myid uniqueidentifier exec insert_test 'dummy', @myid output select @myid 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -