0

我现在有 2 个表,已经定义,
第一个称为wrote秒是publication

在出版物中,我有 2 个领域:

title1, title2 

在写我有3个领域:

Serial number, title1, title2

第二个表外键title1,title2是对第一个表主键(两个字段)的约束。现在,我想
从第二个表(title1,title2

我成功接收了数据,但是每当我尝试删除时,我都会收到一条错误消息,说我没有通过约束,所以我必须先从“写”中删除该行,然后才能从中删除publication,但是每当我删除行时从publication查询返回空(因为它基于已删除的信息)

有没有一种方法可以创建像不是“视图”的“临时表”,并且即使我会从我用来查询的表中删除信息,其中的数据也会被保存?

这是完整的查询:(没有像我在评论中提到的那样创建一个新表)

create or replace view WritersPerPub as
select wrote.ven_title as v2, wrote.pub_title as p2, count(pub_title) as NumOfWriters
from wrote
group by pub_title,ven_title;

create or replace view NathanWrote as
select publication.ven_title as v1 , publication.pub_title as p1
from publication,wrote
where wrote.ven_title = publication.ven_title AND
      wrote.pub_title = publication.pub_title AND
      wrote.serial_number = (   select serial_number
                                from researcher as r
                                where r.firstname = 'Nathan' AND r.surname = 'Keller');

create or replace view WrittenOnlyByNathan as
select NathanWrote.v1, NathanWrote.p1
from WritersPerPub, NathanWrote
where WritersPerPub.p2 = NathanWrote.p1 AND
      WritersPerPub.v2 = NathanWrote.v1 AND
      WritersPerPub.NumOfWriters = 1;

# Delete Nathan Keller from 'Wrote' table
delete from wrote
where serial_number = (select r.serial_number as rf1
                        from  researcher as r
                        where r.firstname = 'Nathan' AND r.surname = 'Keller');

delete from publication USING publication INNER JOIN WrittenOnlyByNathan 
where publication.pub_title = WrittenOnlyByNathan.p1 AND
  publication.ven_title = WrittenOnlyByNathan.v1;
4

0 回答 0