我有两张桌子:
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)运行此查询,那么对于上述条件,运行多个查询或内部联接是否更昂贵(性能方面)?
注意:假设表没有参照完整性。所以,我没有使用级联删除。