SQL 记录有没有系统顺号我的数据库有这样几个字段:公司名称,姓名,地址,备注注:1.以上字段都是varchar类型
2.数据库不能再增加自增,或是时间类型的字段
现在我怎么样才能根插入的顺序进行排序?

解决方案 »

  1.   

    select * from(
    select *,rn=row_number()over(order by (select 1)) from tb
    )t order by rn
    其实,插入顺序并不是一个有意义的顺序,应该找一个列来排序.
      

  2.   

    select *,(select count(id) from tb where  id<=t.id) from tb t
      

  3.   


    谢谢回复,我上面说了这个表没有主键或是int类型的id这样的字段,存的都是一些字符信息
      

  4.   

    没有的话 这样select *,px=identity(int,1,1) into #t from tbselevt * from #t
      

  5.   

    --修改一下
    select *,px=identity(int,1,1) into #t from tbselect * from #t