如何使表中id按增序排列,id是自设的,现在是乱的,如何写sql语句?

解决方案 »

  1.   

    select * into # from tb order by id
    truncate table tb
    insert into tb select * from #
    drop table #
      

  2.   

    如果想另生成id
    可用
    select identity(int,1,1) as iden,*  into # from tb
    truncate table tb
    insert into tb select iden,col2,col3.. from #
    drop table #
      

  3.   

    使用下面的语句将ID排序
    declare @i int
    select @i = 0
    update table表 set @i = @i+1,id = @i  
    然后将列设置为自增加的。
      

  4.   

    要么把id列设置为标识列,要么在id列上建立索引(升序)
      

  5.   

    hrb2008() 的方法不行
    select identity(int,1,1) as iden,*  into # from tb
    truncate table tb
    insert into tb select iden,col2,col3.. from #
    drop table #
    tb表中的,iden为标识符号,插入时会报错!应该是:
    set identity_insert tb on select identity(int,1,1) as iden,*  into # from tb
    truncate table tb
    insert into tb select iden,col2,col3.. from #
    drop table #
    set identity_insert tb off