我有一个包含四个表的数据库。图中关系图如下:
这是行:
现在我正在尝试删除所有者 ID 为 OW1
的所有者。因为 id 是所有者表中的主键和其他表中的外键,所以不允许我删除该行。这是我尝试过的 SQL:
delete from owners
where ownerid = 'OW1' and petid = 'PT1'
它返回:ORA-02292: integrity constraint (TEST_1.ADDRESSES_OWNERS_FK) violated - child record found
而且我不允许在关系图中将删除规则设置为“CASCADE”。请帮忙 :(
最佳答案
好吧,如果一个匿名块算作一个语句,只需将您的删除包裹在一个块中:
begin
delete from addresses where ownerid = 'OW1';
delete from contacts where ownerid = 'OW1';
delete from pets where ownerid = 'OW1';
delete from owners where ownerid = 'OW1';
end;
/
SQL Fiddle 。似乎有点作弊,但如果这些是你得到的条件......