1.使用临时表
可以使用select into 创建临时表,在第一列,加入Identify(int,1,1)作为行号,
这样在产生的临时表中,结果集就有了行号.也是目前效率最高的方法.
这种方法不能用于视图
代码:
set nocount on
select IDentify(int,1,1) 'RowOrder',au_lname,au_fname into #tmp from authors
select * frm #tmp
drop table #tmp
可以使用select into 创建临时表,在第一列,加入Identify(int,1,1)作为行号,
这样在产生的临时表中,结果集就有了行号.也是目前效率最高的方法.
这种方法不能用于视图
代码:
set nocount on
select IDentify(int,1,1) 'RowOrder',au_lname,au_fname into #tmp from authors
select * frm #tmp
drop table #tmp