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)
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)
delete tableB
from tableA,tableB
where tableA.id=tableB.id
and tableA.del=1
如果tableA只存标记为删除的记录的ID,去掉Del字段,那么删除语句可改为:
delete from B where ID in (select ID from A)
delete tableB
from tableA,tableB
where tableA.id=tableB.id
and tableA.del=1
delete t from tableB t where exists (select 1 from tableA where id=t.id and del = 1)