假设有表A(id,name)
我想表中的数据,按顺序更新
我是这样写的:
update A set name=“张三” WHERE (id IN
          (SELECT TOP 100 PERCENT id
         FROM A  ORDER BY id))
为什么不是按顺序更新,怎样保证按id顺序更新,谢谢!!

解决方案 »

  1.   

    Id 是主键 或者有unique属性吗
      

  2.   


    create table test(id int,name char(1))
    goinsert test select 3,'a'
    union all select 2,'a'
    union all select 4,'a'
    union all select 1,'a'
    union all select 5,'a'
    goupdate a
    set name = 'b'
    from test a
    where id in(
    select top 3 id from test order by id
    )select * from test order by id
    godrop table test
    go/**
    1 b
    2 b
    3 b
    4 a
    5 a
    **/
      

  3.   

    的不是已经用order by排序了吗
      

  4.   

    去掉percent.create table test(id int identity(1,1),name char(1))
    goinsert test 
    select top 200 'a' from sysobjects a,sysobjects b
    goupdate test
    set name = 'b'
    where id in(select top 100 percent id from test order by id) --更新了200*100%=200条,如果不加percent,只更新前100条select * from test
    /*
    1    b
    2    b
    3    b
    4    a
    5    a
    */
    drop table test
      

  5.   


    SET ROWCOUNT 100
    update A set name=“张三”如果是100 PERCENT 那就:
    SELECT TOP 100 PERCENT * FROM A 
    SET ROWCOUNT @@rowcount
    update A set name='张三'