create table test(id int
)insert into test select nullinsert into test select nullinsert into test select null
insert into test select 230
insert into test select 250
insert into test select 433
select * from test
/*
将id列更新为如下形式id
1
2
3
4
5
6更新之后把id列设置为identity(1,1)进行递增,不知道可不可以
*/
drop table test

解决方案 »

  1.   


    create table test(id int)
    insert into test select null
    insert into test select null
    insert into test select null
    insert into test select 230
    insert into test select 250
    insert into test select 433
    godeclare @i int
    set @i=0update test set @i=@i+1,id=@iselect * from test
    godrop table test
    go
      

  2.   

    --这种方式最简单declare @i intset @i=0update 表名 set @i=@i+1,id=@i
      

  3.   

    create table test(id int
    )insert into test select nullinsert into test select nullinsert into test select null
    insert into test select 230
    insert into test select 250
    insert into test select 433
    select * from testselect identity(int,1,1) as sid,id into #t from test
    select id = sid from #t
    drop table #tdrop table test
      

  4.   

    更新之后把id列设置为identity(1,1)进行递增,不知道可不可以
    -------------------------------------------------------------
    只能删除并重建ID列,无法修改。
      

  5.   

    更新之后把id列设置为identity(1,1)进行递增,不知道可不可以
    ---------------------------------------------------------
    要是这样的话:alter table test add bh int identity(1,1) 
        
    alter table test drop column idexec sp_rename 'test.bh','id','column'