set rowcount 10
while exists(select 1 from Dv_topic  where Boardid=75)
delete from Dv_topic  where Boardid=75
set rowcount 0

解决方案 »

  1.   

    set nocount on
    set rowcount 500
    while exists(select 1 from Dv_topic  where Boardid=75)
    delete from Dv_topic  where Boardid=75
    set rowcount 0
    set nocount off
      

  2.   

    --第批删除500条,直到没有满足条件的记录set rowcount 500
    delete from Dv_topic  where Boardid=75
    while @@rowcount>0
        delete from Dv_topic  where Boardid=75
    set rowcount 0
      

  3.   

    set rowcount 500
    while exists(select 1 from Dv_topic  where Boardid=75)
    delete from Dv_topic  where Boardid=75
    set rowcount 0
      

  4.   

    --如果 Boardid 上没有索引,建议在上面建立一个索引再删除
    --如果保留的记录很少,建议用临时表来处理删除select * into #t from Dv_topic  where Boardid<>75
    truncate table Dv_topic  
    set xact_abort on
    begin tran
        insert Dv_topic select * from #t
        drop table #t
    commit tran