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 2007-03-20 09:09  ★金★  阅读(2138)  评论(1编辑  收藏  举报

导航