使用Oracle 11g中的连接条件从两个表中删除数据

时间:2014-04-07 04:36:45

标签: sql oracle

DELETE tbemp.emp_id, 
        tbadd.emp_id 
FROM  TBEMPLOYEE tbemp 
JOIN TBADDRESS tbadd ON (tbemp.emp_id=tbadd.emp_id)

Oracle 11g无法编译它

2 个答案:

答案 0 :(得分:1)

此删除语句在Oracle中无效。还有其他删除声明,一个可能是

DELETE FROM TBEMPLOYEE tbemp 
WHERE EXISTS (select 'x' 
                from TBADDRESS 
               where tbemp.emp_id=tbadd.emp_id);

答案 1 :(得分:0)

您无法通过加入直接从多个表中删除。

但您可以使用ON DELETE CASCADE强制执行外键约束。

ALTER TABLE tbaddress ADD CONSTRAINT fk_emp FOREIGN KEY (emp_id) REFERENCES tbemployee (emp_id) ON DELETE CASCADE;

DELETE FROM tbemployee; -- This also deletes referencing keys from tbaddress