如何在 Oracle 11g 中使用 SQL Developer 进行删除级联?

发布于 2024-09-28 19:34:25 字数 122 浏览 5 评论 0原文

我正在尝试从数据库中的一个表中删除一条记录,但另一个表引用了该行(外键)。所以我想使用Oracle 11g中的SQL Developer进行删除级联。我该怎么做?

I am trying to delete a record from one table in my db, but another table has references to this row (foreign keys). So I want to make on delete cascade using SQL Developer in Oracle 11g. How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夢归不見 2024-10-05 19:34:25

回答OP的技术问题:
在 SQL Developer 中,您可以使用外键引用编辑(子)表。从左侧的树视图中选择“约束”,然后选择有问题的外键。在“引用约束”表单中,有一个名为“删除时”的下拉菜单。从该下拉列表中选择“级联”。

To answer the OP's technical question:
In SQL Developer, you edit the (child) table with the foreign key reference. Select "Constraints" from the treeview on the left and then select the foreign key in question. In the "Referenced Constraint" form there is a drop down named "On Delete". From that drop down, choose "Cascade".

樱娆 2024-10-05 19:34:25

如果您尝试删除(父)表中的行,并且其他(子)表具有对其的外键引用,那么

ORA-02292: integrity constraint (XXXXXX) violated.

每当删除父记录时,都会导致删除所有子行,您指定“ON DELETE级联”选项。

CREATE TABLE Dept_tab (
    Deptno  NUMBER(3) CONSTRAINT Dept_pkey PRIMARY KEY, 
    Dname   VARCHAR2(15), 
    Loc     VARCHAR2(15), 
                CONSTRAINT Dname_ukey UNIQUE (Dname, Loc), 
                CONSTRAINT Loc_check1 
                    CHECK (loc IN ('NEW YORK', 'BOSTON', 'CHICAGO')));

CREATE TABLE Emp_tab ( 
    Empno    NUMBER(5) CONSTRAINT Emp_pkey PRIMARY KEY, 
    Ename    VARCHAR2(15) NOT NULL, 
    Job      VARCHAR2(10), 
    Mgr      NUMBER(5) CONSTRAINT Mgr_fkey REFERENCES Emp_tab,
    Hiredate DATE, 
    Sal      NUMBER(7,2), 
    Comm     NUMBER(5,2), 
    Deptno   NUMBER(3) NOT NULL 
             CONSTRAINT dept_fkey REFERENCES Dept_tab ON DELETE CASCADE);

在这种情况下,如果从部门表中删除一行,则不会引发默认情况下的错误,而是删除员工表中的所有员工。

这与工具(SQL Developer)无关...

If you are trying to delete rows in a (parent) table and other (child) tables have foreign key references to it, then it will cause the

ORA-02292: integrity constraint (XXXXXX) violated.

TO delete all the child rows whenever a parent record is removed, you specify the "ON DELETE CASCADE" option.

CREATE TABLE Dept_tab (
    Deptno  NUMBER(3) CONSTRAINT Dept_pkey PRIMARY KEY, 
    Dname   VARCHAR2(15), 
    Loc     VARCHAR2(15), 
                CONSTRAINT Dname_ukey UNIQUE (Dname, Loc), 
                CONSTRAINT Loc_check1 
                    CHECK (loc IN ('NEW YORK', 'BOSTON', 'CHICAGO')));

CREATE TABLE Emp_tab ( 
    Empno    NUMBER(5) CONSTRAINT Emp_pkey PRIMARY KEY, 
    Ename    VARCHAR2(15) NOT NULL, 
    Job      VARCHAR2(10), 
    Mgr      NUMBER(5) CONSTRAINT Mgr_fkey REFERENCES Emp_tab,
    Hiredate DATE, 
    Sal      NUMBER(7,2), 
    Comm     NUMBER(5,2), 
    Deptno   NUMBER(3) NOT NULL 
             CONSTRAINT dept_fkey REFERENCES Dept_tab ON DELETE CASCADE);

In this case , if a row from the department table is deleted, instead of raising an error which is the default case, it will delete all the employees form the employee table.

This has nothing to do with the tool (SQL Developer)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文