select id=identity(int,1,1),* into #t from 表1
select * form #t

解决方案 »

  1.   

    alter table 表1 add id int identity(1,1)
    select id,字段1,字段2
    from 表1
    alter table 表1 drop column id
      

  2.   

    select  id=(case when 字段2='a1'  then 1
                 when 字段2='b1'  then 2
                else 3 end),*  from 表
      

  3.   

    TO Softlee81307(孔腎):要是有100条记录,我不是写死了?
    大家帮忙想啊!
      

  4.   

    select id=identity(int,1,1),* from 表1
      

  5.   

    TO:lengxiaowei(小伟)
    我试了一下,提示只有INTO子句中,才能用identity函数。难道真的没在办法吗?
      

  6.   

    select id=identity(int,1,1),* into #t from 表1
    select * form #t
      
      

  7.   

    select id=identity(int),* into #t from 表1
    select * form #t
    用不着改表结构的嘛
      

  8.   

    select id=identity(int,1,1),* into #t from 表1 order by 字段2select * form #t