select identity(int1,1) as id,* from table

解决方案 »

  1.   

    select identity(1,1) as id,* into #tem from table
    go
    select * from #tem
      

  2.   

    select identity(int,1,1) as id,* into #tem from table
    go
    select * from #tem
      

  3.   

    1.
    select id=identity(int,1,1),* into #tb from 表
    select * from #tb   --从临时表中查结果
    drop table #tb --删除临时表
      

  4.   

    2.
    alter table 表 add id int identity(1,1)       --为查询添加标识字段
    select * from 表               --查询结果
    alter table 表 drop column id  --删除为查询准备的标识字段
      

  5.   

    alter table 表 add id int identity(1,1)       --为查询添加标识字段
    select * from 表               --查询结果
    alter table 表 drop column id  --删除为查询准备的标识字段