alter table MyTbl add MyID int identity(1,1)

解决方案 »

  1.   

    select  
    MyId=identity(int,1,1)
    No1,
    MyName
    from MyTbl
      

  2.   

    select  MyId=identity(int,1,1),No1,MyName from MyTbl
      

  3.   

    SQL Server没有系统函数来支持显示rowid,不知道SQL Server2005是否支持
    可以借用临时表处理或变通处理
      

  4.   

    if object_id('tempdb..#') is not null drop table #
    go
    select identity(int, 1, 1) as id, * into # from test
    select * from #
    drop table #
      

  5.   

    select
        MyID=(select count(*) from MyTbl where No1<a.No1 or (No1=a.No1 and MyName<=a.MyName))
        a.* 
    from 
        MyTbl a
      

  6.   

    identity(int,1,1)只能用在select ..带有into子句时才可以
      

  7.   

    select  
    MyId=identity(int,1,1)
    No1,
    MyName
    Into #
    from MyTblselect * from #drop table #
      

  8.   

    sorry 错了SELECT 语句中有 INTO 子句时,才能使用 IDENTITY 函数。
      

  9.   

    select myid=(select count(*) from tb1 where tb1.no1<a.tb2.no1),* from tb1 a
      

  10.   

    2005可以select  
    row_number() over(order by No1,MyNane) as MyId
    No1,
    MyName
    from MyTbl
      

  11.   

    对的 row_number()在2005中被支持 Ex:USE AdventureWorks;
    GO
    WITH OrderedOrders AS
    (SELECT SalesOrderID, OrderDate,
    ROW_NUMBER() OVER (order by OrderDate)as RowNumber
    FROM Sales.SalesOrderHeader ) 
    SELECT * 
    FROM OrderedOrders 
    WHERE RowNumber between 50 and 60;
      

  12.   

    select myid=(select count(*) from tb1 where tb1.no1<a.tb2.no1),* from tb1 a
    这种方法只能在原表是在no1上排序后,且no1没有重复值才能得到lz想要的结果吧!