Oracle PLSQL级联删除不起作用?

问题描述 投票:0回答:2

我有一些带有外键的表应删除。我将“放在删除级联”放到需要的地方,但是当我尝试删除表时,出现以下错误:

*Cause:    An attempt was made to drop a table with unique or
           primary keys referenced by foreign keys in another table.

这是我要删除的表:

DROP TABLE Author;
CREATE TABLE Author (
    id NUMBER(4) NOT NULL,
    first_name VARCHAR2(30) NOT NULL,
    last_name VARCHAR2(30) NOT NULL,
    date_of_birth DATE NOT NULL,
    date_of_death DATE NULL,
    CONSTRAINT Author_PK PRIMARY KEY (id)
);

这是与作者表有关的表:

CREATE TABLE Book (
    id NUMBER(4) NOT NULL,
    author NUMBER(4) NULL,
    title VARCHAR2(30) NOT NULL,
    ISBN VARCHAR2(13) NOT NULL,
    book_language VARCHAR2(2) NOT NULL,
    book_genre VARCHAR2(20) NOT NULL,
    CONSTRAINT Book_PK PRIMARY KEY (id),
    CONSTRAINT Book_Author FOREIGN KEY (author) REFERENCES Author(id) ON DELETE cascade
);
sql oracle sql-delete ddl cascade
2个回答
0
投票

DROP是DDL。 DELETE(DML)与它无关(受创建外键约束的方式影响)。

首先删除子表;然后删除其父项。


0
投票

我现在在@a_horse_with_no_name的帮助下解决了它如果您有相同的问题,只需写

drop table table_name cascade constraints;

推荐问答
热门问答
最新问答