select *,identity(int,1,1) into #t from tablenameselect * from #tdrop table #t

解决方案 »

  1.   

    假如你的id为唯一键,那么:
    select *,(select count(*) from t where id<=a.id) sn from t a order by sn
    没有,那么:
    select *,identity(int,1,1) sn into #t from t
    select * from #t order by sn
      

  2.   

    --如果有主键,可以用:
    select 序号=(select sum(1) from 表 where 主键<=a.主键),* from 表 a
    order by 主键--否则用临时表,即楼上的.
      

  3.   

    假如你的id为唯一键?可以是其他的,如name,address等其他字段,只要有个唯一字段就可以。或者你可以有两个,或两个以上的字段构成主键,那么where id<a.id and id2<a.id2...
      

  4.   

    谢谢,已经测试通过了,但我想序号生成是用
    select 序号=(select sum(1) from 表 where 主键<=a.主键),* from 表 a
    order by 主键
    为什么这样可生成一个序号?谢谢大家.
      

  5.   

    测试是通过了.但速度很慢,不加序号(行号)打开70000多条数据花了7秒.如是用
    select 序号=(select sum(1) from 表 where 主键<=a.主键),* from 表 a
    order by 主键
    这个方法打开表,时间为25分钟.不知有没有高手指导有更快的办法.谢谢了.