select *,id=(select count(*) from 表 a where a.id<表.id) from 表

解决方案 »

  1.   

    select identity(int,1,1) as id,* from tablename where 条件
      

  2.   

    用identity(int,1,1)  第一个参数是数据类型,第二个参数是起始位置,第三个参数是步长(也就是每次自增1)
      

  3.   

    例:
    select identity(int , 1, 1) as id , Field1 ,Field2  into NewTable from Tableselect * from NewTable注:NewTable为物理表。
      

  4.   


    回复人: daijingjie2002(艰苦创业) ( ) 信誉:97  2005-01-18 11:50:00  得分: 0  
     
     
       select *,id=(select count(*) from 表 a where a.id<表.id) from 表
      
      

  5.   

    daijingjie2002(艰苦创业) 
    你的方法不行,提示没有ID
      

  6.   

    select identity(int , 1, 1) as id , Field1 ,Field2  into NewTable from Table
    这方法我知道,求更为简单的方法
      

  7.   

    可以用临时表
    sql2000中是没有直接的方法了
    听说sql2005中有函数!
      

  8.   

    如果table中存在int型的主键列id,则比较简单select (select count(1) from t1 where id<=a.id) as rowid,* from t1 a不然可能只能用identity了
    oracle中有伪列rownum,很简单。sql2005好像也会引入分析函数,以后也会变得简单的