Sql Server中自动序号的方法

第一种:使用identity函数增加临时表的方法
select id = identity(int,1,1),* into #tmp from table
select * from #tmp
drop table #tmp

在SQL2005中新增了ROW_NUMBER()函数,给我们带来了很多方便,使用方法如下:
SELECT id,ROW_NUMBER() OVER (order by id)as RowNumber FROM Table
有一个方便,as后的别名可以在语句后面作为条件单独使用.

posted on   ★金★  阅读(2145)  评论(1编辑  收藏  举报

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示