ALTER TABLE 表 DROP COLUMN 编号 
ALTER TABLE 表 ADD 编号 int identity(1,1) not null

解决方案 »

  1.   

    pengdali
    我的id可是主键呀。能删掉吗?
      

  2.   

    select * into #t from a2
    go
    truncate table a2
    go
    alter table #t
    drop column id
    go
    insert a2 select * from #t
    go
      

  3.   

    用临时表:
    --备份数据
    select * into #t from a2
    go
    --删除原表数据
    truncate table a2
    --如果不能这样删除,就用下面的这句
    delete from a2
    DBCC CHECKIDENT (a2, RESEED, 1)
    go
    --修改临时表,移动自动编号的id字段
    alter table #t
    drop column id
    go
    --从临时表中导回数据
    insert a2 select * from #t
    go