由于自增字段位数过多,已经使数据库无法很好的完成工作,想把之前的数据删除,然后把最新的数据重排,请教用什么方法最好,谢谢

解决方案 »

  1.   

    select id=identity(int,1,1),[除identity字段外的列] into new
    from old 
      

  2.   

    1、如果只有旧数据,新数据未插入表中
    truncate table 表名
    执行后,再插入新数据,自增列又从1开始了2、如果表中有新旧数据,先删除旧数据,再执行下面语句
    alter table 表名 drop column id
    alter table 表名 add id int identity不过这样自增ID就在最后一列了,但要比select id=identity(int),* into 新表 from 旧表  要快些也可以参考如何把新增列调整第一列的文章
      

  3.   


    --1、如果要清除所有数据,并将自增id从1开始。
    truncate table 表名 --清除所有数据并将自增id重新初始化。
    --2、如果要保留数据,
    select * into # from 表名 --将数据导入临时表
    truncate table 表名  --清除表中数据,并初始化自增id
    insert into 表名(字段1,字段2) select 字段1,字段2 from # --将临时表中数据导回表中。
      

  4.   


    更新字段值自动增加;create table #t(id int ,name varchar(20))
    insert into #t(name) select 'a'
    insert into #t(name) select 'a'
    insert into #t(name) select 'a'
    insert into #t(name) select 'a'
    insert into #t(name) select 'a'
    insert into #t(name) select 'a'declare @i int
    set @i=0update #t set @i=@i+1, id=@Iselect * from #t
      

  5.   

    DBCC CHECKIDENT 

    'table_name'
        [ , {
        NORESEED | { RESEED [ , new_reseed_value ] }
            }
        ]
    )
    [ WITH NO_INFOMSGS ]可以更改标示的
      

  6.   

    如果表没有外键 直接用 truncate table tablename
      

  7.   

    最简单的方法就是先删列再增加也可以把数据导入临时表,truncate表,再导入
      

  8.   

    http://blog.csdn.net/happyflystone/archive/2007/11/25/1901966.aspx
      

  9.   

    select id=identity(int,1,1),[除identity字段外的列] into new 
    from old 
    delete from old 
    set identity_insert old on 
     insert into old select * from old
    不是很麻烦啊!