我想在表中有一列id字段,每当我插入一行数据,它就从1开始自动+1增长,表示已经插入了多少行.

解决方案 »

  1.   

    1.增加自增列id
    alter table 表名
    add  id int identity(1,1)2.查询时增加虚拟自增列
    select identity(int,1,1) as id,* into #tmp from 表名
    select * from #tmp
      

  2.   

    alter table 表名
    add  id int identity(1,1)
    是修改表时,
    如果我在创建表时,可不可以 create table 表名( id int identity(1,1))
    或者我在企业管理器中,创建表时,在"默认值"那里怎么填呢?
      

  3.   

    create table temptest( id int identity(1,1),code nvarchar(10) default 'abc')