如何用语句添加或去除表字段的自增属性
http://expert.csdn.net/Expert/topic/2217/2217137.xml?temp=.8302118

解决方案 »

  1.   

    有数据的话
    ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
    go
    SET IDENTITY_INSERT 表 ON
    go
    update 表 set 编号1=编号
    go
    SET IDENTITY_INSERT 表 OFF
    go
    ALTER TABLE 表 DROP COLUMN 编号 
    go
    exec sp_rename '表.编号1','编号'
    go
      

  2.   

    alter table 表 add 列名 int identity(1,1)
      

  3.   

    add 是增加一列,但现在是已有一列存在。这个语句错在那里呢?alter table InfoClass1 alter column InfoID int IDENTITY(1,1) NOT NULL
      

  4.   

    --不能将现有列直接修改为标识字段.如果要将现有列改为标识字段的话,要用下面的SQL:select * into #t from InfoClass1
    truncate table InfoClass1
    alter table InfoClass1 drop column InfoID
    alter table InfoClass1 add column InfoID int identity(1,1) not null
    set identity_insert InfoClass1 on
    insert into InfoClass1(字段列表) select 字段列表 from #t
    drop table #t