代码改变世界

Sql Server中自动序号的方法

2008-06-25 19:50  Vincent.C  阅读(446)  评论(0编辑  收藏  举报
第一种:使用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后的别名可以在语句后面作为条件单独使用.