如和新建一个列,并将其设置为自增列?见笑了,刚刚开始用sqlserver

解决方案 »

  1.   

    alter table tb
     add id int identity(1,1)
      

  2.   


    ALTER TABLE t
    ADD id int identity(1,1)
      

  3.   

    alter table tbname add id int identity
      

  4.   

    如果是可视化方法建的话,它的列属性里有Identity Specification这一属性
      

  5.   

    --先判断列是否存在,不存在赠新增(假设列名为aa
    if not exists (select * from syscolumns where name='aa' and id in(select id from sysobjects where name='表名'))
    begin
    alter table 表名  ADD  [aa]  [int] NOT NULL IDENTITY (1, 1)
    end
    GO
      

  6.   

    select id from sysobjects where name='表名' 这个不是返回表的ID吗,因该就一个值啊?,那这ID与新建的列名有什么关系