1
我的表看起来像这样:如何让插入顺序的唯一标识符
create table foos(
id uniqueidentifier primary KEY DEFAULT (newsequentialid()),
..
)
所以ID顺序自动生成的,我不会将它设置
我怎么把它插入后的价值? (带有身份证明我正在做insert ... select @@identity
)
我的表看起来像这样:如何让插入顺序的唯一标识符
create table foos(
id uniqueidentifier primary KEY DEFAULT (newsequentialid()),
..
)
所以ID顺序自动生成的,我不会将它设置
我怎么把它插入后的价值? (带有身份证明我正在做insert ... select @@identity
)
Returning the NewSequentialID() after Insert using the Output Clause
的基本思想:
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
您将使用插入id的其他数据再次选择它。那么,你有..
你会:
SELECT id
WHERE ..
这将使该ID