我这里有一个table,里面有个字段ID是自增的,从1.2.3......n
现在表里面存了2条记录,ID的最大值为2。而我手动的把ID值改为了20,改为20之后,3-19这段ID就没有记录了,而以后添加的记录ID就是以20为底数增加(21.22....n),我又添加了10条记录在里面,这时表的ID最大值就是30了。
现在要解决的问题就是:我把ID为20以后的记录删了,如何才能把记录的ID值让它还是以3为底数的增加呢?
各位大虾请指点指点。

解决方案 »

  1.   

    create table #t(id int identity(1,1),num int)insert into #t select 10
    insert into #t select 20
    insert into #t select 30
    insert into #t select 40delete #t where num>=30--用dbcc checkident 重置当前标识值
    dbcc checkident (#t,reseed,2)insert into #t select 50select * from #t
    drop table #t
      

  2.   

    把dbcc checkident 这句注释掉,和没有注释的做一下对比,执行看看效果就知道了。
      

  3.   

    create table T(id int identity(1,1),num int)insert into T select 10
    insert into T select 20
    insert into T select 30
    insert into T select 40
    insert into T select 50delete T where num>=40
    --用dbcc checkident 重置当前标识值
    dbcc checkident (T,reseed,3)
    insert into T select 60select * from T
    drop table T
      

  4.   

    select 10,20,30,40,50,60是什么意思呀?
      

  5.   

    ALTER TABLE `table_name` AUTO_INCREMENT = 3;
      

  6.   

    还有就是我用的数据库是Mysql.