select IDENTITY(int,1,1) new_id ,* into #temp from a where a1>10 select * from #temp
--SQL中只能在生成表的查询语句中使用,不能直接在查询中使用indentity--改为: select new_id=identity(int,1,1),* into #t from a where a1>10 select * from #t --显示结果 drop table #t --完成后删除临时表
select new_id=identity(int,1,1),* into #t from a where a1>10 select * from #t --显示结果 drop table #t
如存在象id这样的唯一列,你可以:select (select sum(1) from a where id<=tem.id and a1>10) new_id,* from a tem where a1>10 order by idorselect (select count(*) from a where id<=tem.id and a1>10) new_id,* from a tem where a1>10 order by id
select * from #temp
select new_id=identity(int,1,1),* into #t from a where a1>10
select * from #t --显示结果
drop table #t --完成后删除临时表
select * from #t --显示结果
drop table #t