比如返回:
A   B
1   dsfsdf
2   sddsfds
3   dsfsdf
...  ...类似于 select identity(1,1), B from tableA但identity(1,1)是错的,正确的语法是什么?

解决方案 »

  1.   

    select row_number over(order by B) as num,* from 表
      

  2.   

    select identity(int,1,1) as id,B into newtable from tableA
      

  3.   

    我的是SQL Server2000的写法.
      

  4.   

    select id=identity(int,1,1),b from tablea
      

  5.   

    或者
    alter table tableA add id int identity(1,1)
      

  6.   

    chuifengde(树上的鸟儿) ( ) 信誉:100    Blog   加为好友  2007-04-19 16:54:49  得分: 0  
     
     
       select id=identity(int,1,1),b from tablea
      
    -------------------------------------
    服务器: 消息 177,级别 15,状态 1,行 1
    仅当 SELECT 语句中有 INTO 子句时,才能使用 IDENTITY 函数。
      

  7.   

    --sql 2005 直接可以用 row_number() over (order by 字段) 方法.
    --sql 2000 中 A: 临时表 B: 临时字段 C:关键字生成序号. 这几种方式.
      

  8.   

    zlp321002(付出最大努力,追求最高成就,享受最佳生活,收获无悔人)说的是对的,谢谢
      

  9.   

    gahade(与君共勉),本来要给你10分的,但一不小心和‘chuifengde(树上的鸟儿)’弄反了,还是非常感谢各位迅速的给出帮助:)
      

  10.   

    原表中如果有唯一列的话 可以这样
    select (select count(*) from t1 where t1.b<=tt1.b)as id ,tt1.b from t1 as tt1 order by b