SQL2000下,有两个表tableA和tableB,tableA 中有两个字段 id(int型),del(bit型),tableB 中只有一个字段 id(int型)。
tableA和tableB中的记录是一一对应的,关联字段就是id。tableA 的del字段值有50%的出现概率是1。
请问在表的记录数分别是100条、10,000条和1,000,000条时,删除tableB中所有在tableA中关联记录的del字段值是1的记录的最高执行效率语句。
下面的语句在大数据量的情况下执行效率肯定是很低的,不知道你在这几种情况下会怎么做。
delete from tableB where id in (select id from tableA where del = 1)

解决方案 »

  1.   

    语句
    delete tableB
    from tableA,tableB
    where tableA.id=tableB.id
    and tableA.del=1
      

  2.   

    tableA 的del字段值有50%的出现概率是1。-----------
    如果tableA只存标记为删除的记录的ID,去掉Del字段,那么删除语句可改为:
    delete from B where ID in (select ID from A)
      

  3.   

    delete from tableB t where exists (select 1 from tableA where id=t.id and del = 1)
      

  4.   

    Yang_写的语句可以执行,谢谢参与,学习
    delete tableB
    from tableA,tableB
    where tableA.id=tableB.id
    and tableA.del=1
      

  5.   

    --更正
    delete t from tableB t where exists (select 1 from tableA where id=t.id and del = 1)
      

  6.   

    去见合作伙伴,晚上再测试wufeng4552的速度。