我有两张桌子:
table1 (id, name, connte)
table2 (id, name, connte)
它们通过table1.connte和table2.connte连接.每个都包含100条记录.
现在,如果我想从table1中删除id = 20的记录及其在table2中的相应子项,那么最好是执行以下操作:
DELETE d1,d2 FROM table1 d1 INNER JOIN table2 d2 ON d1.connte= d2.connte WHERE d1.id = 20
或以下:
select connte from table1 where id = 20
--Store connte in a variable say aabc--
delete from table2 where connte = aabc -> execute this first
delete from table1 where id = 20 -> execute this second
如果我想要删除的记录只有一个父项和一个子项(这里是table1.id = 20),那么对整个表进行内连接是不是很昂贵?
我正在从JAVA(所以JDBC)运行此查询,因此对于上述条件,运行多个查询或内部联接是否更昂贵(性能明智)?
注意:假设表没有参照完整性.所以,我没有使用级联删除.