alter table tablename add id int identity(1,1)
go
update tablename 以前的序号=right(cast(100000000+id as varchar(10),8)

解决方案 »

  1.   

    alter table tablename add id int identity(1,1)
    go
    update tablename 以前的序号=right(cast(100000000+id as varchar(10)),8)
      

  2.   

    create table t(id char(8))
    insert t select '00000456'insert t select right('0000000'+convert(varchar,convert(int,isnull(max(id),'0'))+1),8) from t
    select * from t
    /*
    id       
    -------- 
    00000456
    00000457
    */
    drop table t
      

  3.   

    --如果你是想更新现有在ID字段为8位,可参考下例
    --drop table tb
    create table tb(id varchar(8))
    insert into tb select top 10 id from sysobjects
    --select * from tb
    update tb set id=right(cast(100000000+id as varchar(9)),8)
    --select * from tb
      

  4.   

    DECLARE @id int
    SET @id = 100000000UPDATE 你的表 SET
        @id = @id + 1,
        编号 = RIGHT(@id, 8)
      

  5.   

    to:zjcxc(邹建)
    老大一出
    谁与争锋?!!