如在customer表中的ID字段,原来为10000起,自增1
现在想改为20000起,自增1
通过语句完成。

解决方案 »

  1.   

    create table tb(id int, ident int identity(10000, 1))
    insert into tb
    select 1000 union all
    select 1001 union all
    select 1002 union all
    select 1003 DBCC CHECKIDENT('tb', RESEED, 20000)insert into tb
    select 1004 union all
    select 1005 union all
    select 1006 union all
    select 1007 select * from tb
    drop table tb结果:
    id      ident
    100 10000
    101 10001
    102 10002
    103 10003
    104 20001
    105 20002
    106 20003
    107 20004
      

  2.   

    方法如下:
    1.先将自增列修改为不自增,否则无法更新,
    2,用以下代码就可实现,比如改为从1001开始,declare @i int
    set @i=1000update shengchandan_master
    set rowid=@i,@i=@i+1
    3,再将那个列修改成自增
      

  3.   

    先删除,再加入create table #tb(id int, ident int identity(10000, 1))
    insert into #tb
    select 1000 union all
    select 1001 union all
    select 1002 union all
    select 1003 alter table #tb
    drop column identalter table #tb
    add ident int identity(20000,1)
    select * from #tb
      

  4.   

    不能再已有的field上进行直接的改动.
    只有先删掉再加上去,就像LS的
      

  5.   

    DBCC CHECKIDENT('tb', RESEED, 20000)
      

  6.   

    DBCC CHECKIDENT('tb', RESEED, 20000)alter table #tb
    add ident int identity(20000,1)
    都可以!
      

  7.   

    create table tb(id int, ident int identity(10000, 1))
    insert into tb
    select 1000 union all
    select 1001 union all
    select 1002 union all
    select 1003 DBCC CHECKIDENT('tb', RESEED, 20000)insert into tb
    select 1004 union all
    select 1005 union all
    select 1006 union all
    select 1007 SELECT * FROM tb
    ------------------------
    id          ident       
    ----------- ----------- 
    1000        10000
    1001        10001
    1002        10002
    1003        10003
    1004        20001
    1005        20002
    1006        20003
    1007        20004(所影响的行数为 8 行)
      

  8.   

    DBCC   CHECKIDENT( 'tb ',   RESEED,   20000)  这个是最简便的方法,
    不过可能会引起重复