sql identity怎么在select中用

2025-02-26 05:17:01
推荐回答(3个)
回答1:

select identity(int,1,1) as id,pzid
into #temp
from pz
select * from #temp
drop #temp

回答2:

在SQL语句后面加上select @@identity就可以了,这是针对插入新列用的,查询没必要

回答3:

要 1,2,3,4 这种顺序的。
就直接 ROW_NUMBER 就可以了

例如:
select
ROW_NUMBER() OVER(ORDER BY (SELECT 1)) id,
pzid
from pz