各位老大,我的sql2005有张表,里面有数据。现在我想给一个字段加identity的属性,但是好像不能加。请问可不可以再保留数据的基础上直接加?如果可以应该用什么语句?谢谢

解决方案 »

  1.   

    alter table add column columnname int identity(1,1)
      

  2.   

    在SQL Server 2000中这样做:1、建新表,将字段直接建为identity属性
    2、将identity_insert设置为off,将原表数据insert过去
    3、更新identity当前值为表内最大值
    4、删除原表
    5、重命名新表为原表表名
      

  3.   

    如果直接,alter table add column columnname int identity(1,1)columnname 是为空的吧,用子陌的方法就可以了