在SQL里怎么写循环呀??用循环也就好办了。

解决方案 »

  1.   

    事务加锁:
    begin tran
    select * into test1 from test with(ROWLOCK) where testcode>5
    delete from test with(ROWLOCK) where testcode>5commit tran
      

  2.   

    begin tran
    select * into test1 from test with(ROWLOCK) where testcode>5
    delete from test with(ROWLOCK) where testcode>5
    if @@error <> 0
    rollback tran
    else
    commit tran