各位大侠好,问题是这样的,我程序先用了select top 500 * from biaoA 
然后把这些数据逐条导出到另外一个表中,然后用update biaoA set ziduanA='1' where ziduanB in (select top 500 ziduanB from biaoA )
问题是我两次取出来的前500条不相同,,请问为什么??
在运行这个程序的同时,有其他程序时时访问这个表。有可能有插入操作。
请问有什么好的解决办法吗?

解决方案 »

  1.   

    --trybegin tran
    SET ROWCOUNT 500
    update biaoA set ziduanA='1'
    SET ROWCOUNT 0
    commit tran
      

  2.   

    我程序先用了select top 500 * from biaoA 
    然后把这些数据逐条导出到另外一个表中,--如果另一个表已经存在
    insert  into tableother(...)
    select top 500 * from biaoA --如果另一个表不存在 
    select top 500 * into tableother from biaoA --更新
    update biaoA 
    set ziduanA='1' where ziduanB in (select  ziduanB from tableother )
      

  3.   

    top 500 * 跟 top 500 ziduanB是不一样的,默认字段排序不一样,有可能*是按表索引默认升序排序,ziduanB是按字段默认升序排序
      

  4.   

    select top 500 * from biaoA 后面加个排序如select top 500 * from biaoA order by id
      

  5.   

    实际程序中 (select top 500 ziduanB from biaoA )两条语句是一样的,都是select top 500 ziduanB  都是同一个字段,,
      

  6.   

    TO: coolingpipe(冷箫轻笛)  我不能用另一个表,另一个表是有数据会被取出做一些处理,然后给删除拉。所以修改语句的时候不能用另一个表做为参考条件
      

  7.   

    set xact_abort on
    begin tran
    select top 500 ziduanB into #tmp from biaoA  with(xlock)
    ....
    commit