SQL2005,数据库建好,表也有了,内容还无,ID是INT类型字段忘记让他自动编号了,现在要改,该怎么改

解决方案 »

  1.   

    直接在SQL Server Management Studio增加该列的自增属性即可.
      

  2.   

    如果要用语句,则参考如下:
    有关自增列的相关语句--identity列与普通列互换
    CREATE TABLE t1(ID int IDENTITY,A int)
    GO
    --插入记录
    INSERT t1 VALUES(1)
    GO--1. 将IDENTITY(标识)列变为普通列
    ALTER TABLE t1 ADD ID_temp int
    GOUPDATE t1 SET ID_temp=ID
    ALTER TABLE t1 DROP COLUMN ID
    EXEC sp_rename N't1.ID_temp',N'ID',N'COLUMN'
    INSERT t1 VALUES(100,9)
    GO--2. 将普通列变为标识列
    CREATE TABLE t1_temp(ID int,A int IDENTITY)
    SET IDENTITY_INSERT t1_temp ON
    INSERT t1_temp(ID,A) SELECT * FROM t1
    SET IDENTITY_INSERT t1_temp OFF
    DROP TABLE T1
    GOEXEC sp_rename N't1_temp',N't1'
    INSERT t1 VALUES(109999)
    GO--显示处理结果
    SELECT * FROM t1
    /*--结果:
    ID          A 
    ----------------- ----------- 
    1           1
    100         9
    109999      10
    --*/
      

  3.   

    alter table 表
     alter column ID int identity(1,1)
      

  4.   

    alter table tb
     alter column ID int identity(1,1) not null PRIMARY KEY
    --是否需要设置主键
      

  5.   

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

  6.   


    alter table tb
    alter column ID int identity(1,1) not null PRIMARY KEY
      

  7.   

    sql2005
     SQL Server Management Studio Express中选择你要修改的列查看属性 标示规范 改为 是 就可以了
      

  8.   

    sql2005
     SQL Server Management Studio Express中选择你要修改的列查看属性 标示规范 改为 是 就可以了