如何获取插入的顺序唯一标识符 [英] how to get inserted sequential uniqueidentifier
本文介绍了如何获取插入的顺序唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的桌子是这样的:
create table foos(
id uniqueidentifier primary KEY DEFAULT (newsequentialid()),
..
)
所以id是顺序自动生成的,我没设置
so the id is sequentially generated automatically, I'm not setting it
如何在插入后获取它的值?(身份我正在做 insert ... select @@identity
)
how do I get it's value after the insert ?
(with identity I was doing insert ... select @@identity
)
推荐答案
基本思路:
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
这篇关于如何获取插入的顺序唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文