因为删除了很多条记录信息。id排序出现了断层
例如:1
      2
      3
    ......      1001
      1002
      2001
     
怎样让他们重新初始化排序,1,2,3,......1001,1002,1003,......

解决方案 »

  1.   

    在tb表中查找断层
    select top 5000 identity(int,1,1) as id into #t from sys.syscolumns a,sys.syscolumns b
    select * from #t where id not in(select id from tb)
      

  2.   


    如果是SQL2005,可以排序如下。
    SELECT ROW_NUMBER() OVER(ORDER BY GETDATE()) AS RID,* 
    FROM LI 
    这样可以取得新的ID 
      

  3.   

    Select * Into Table From Table1
    Rename Table关注
      

  4.   

    declare @id int
    set @id=0update tb
      set @id=@id+1,id=@id
      

  5.   

    我用的是sql2000
     而且这几种方法,不知怎么使用。
    如果你们真的会,那就请详细说明。。谢谢
      

  6.   


    declare @table table (id int,col varchar(10))
    insert into @table
    select 1,'11' union all
    select 2,'22' union all
    select 3,'44' union all
    select 1001,'66' union all
    select 1002,'88' union all
    select 2001,'99'select * from @table
    /*
    id          col
    ----------- ----------
    1           11
    2           22
    3           44
    1001        66
    1002        88
    2001        99
    */
    update @table 
    set id=cc.row
    from 
    (
    select row_number() over (order by a.id) as row ,a.id,a.col from @table a left join @table b on a.id=b.id
    ) cc left join @table d on cc.id=d.idselect * from @table
    /*
    id          col
    ----------- ----------
    1           11
    2           22
    3           44
    4           66
    5           88
    6           99
    */
      

  7.   

    --假设表tb内容如下   
      create   table T   (id   int ,aa   varchar(2),bb   varchar(3))   
      insert   T   values(1,'11','111')   
      insert   T   values(3,'22','222')   
      insert   T   values(5,'33','333')
      
    select id,aa,bb from T
    id          aa   bb
    ----------- ---- ----
    1           11   111
    3           22   222
    5           33   333(3 行受影响)alter table T  DROP COLUMN id
      --将id列删除外 
    alter table T  add id int identity(1,1)
      --添加新ID标识列
    select id,aa,bb from Tid          aa   bb
    ----------- ---- ----
    1           11   111
    2           22   222
    3           33   333(3 行受影响)
      

  8.   


    --sql2000 里可以这样
    declare @table table (id int,col varchar(10))
    insert into @table
    select 1,'11' union all
    select 2,'22' union all
    select 3,'44' union all
    select 1001,'66' union all
    select 1002,'88' union all
    select 2001,'99'select * from @tabledeclare @table2 table(id int identity(1,1) ,col varchar(10))insert into @table2 (col)
    select col from @table order by idselect * from @table2
      

  9.   

    1.使用truncate table刪除數據 
    2.checkident重置起始值
      

  10.   


    DECLARE @TB TABLE([id] INT)
    INSERT @TB 
    SELECT 1 UNION ALL 
    SELECT 2 UNION ALL 
    SELECT 3 UNION ALL 
    SELECT 1001 UNION ALL 
    SELECT 1002 UNION ALL 
    SELECT 2001declare @id int
    set @id=0update @TB
      set @id=@id+1,id=@idSELECT *
    FROM @TB 
    /*
    id
    -----------
    1
    2
    3
    4
    5
    6
    */
      

  11.   


    1,先把自曾长列删除
    2,在把数据插入临时表#T
    select identity(int,1,1)as id,* into #T from 你的表
    3,把原表数据
    delete from 你的表
    4,还原数据(你的表的表少一个id字段要加上)
    insert into 你的表
    select * from #T
    5,需要把自曾长列属性加上!你在加上!
      

  12.   

    --先把原来的编号列(假设ID)删除
    alter table tb drop column id
    2,在把tb表数据插入临时表#T,并且从新加入ID列
    select identity(int,1,1)as id,* into #T from TB
    3,把原表数据删除
    delete from tb
    4,还原数据(你的表的表少一个id字段要加上)
    select * 
    into tb
    from #t