开发者

how to get inserted sequential uniqueidentifier

开发者 https://www.devze.com 2023-03-11 23:32 出处:网络
my table looks like this: create table foos( id uniqueidentifier primary KEY DEFAULT (newsequentialid()),

my table looks like this:

create table foos(
id uniqueidentifier primary KEY DEFAULT (newsequentialid()),
..
)

so the id is sequentially generated automatically, I'm not setting it

how do I get it's value after the insert ? (with identity I w开发者_运维问答as doing insert ... select @@identity)


Returning the NewSequentialID() after Insert using the Output Clause

The basic idea:

create table foos(id uniqueidentifier primary KEY DEFAULT (newsequentialid()))

declare @Ids table(id uniqueidentifier)

insert foos
output inserted.id into @Ids
default values

select *
from @Ids


You would use the other data that got inserted with the id to select it out again. So where you have the .. you would have:

SELECT id
WHERE ..

which would return the id

0

精彩评论

暂无评论...
验证码 换一张
取 消