• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2133
  • Last Modified:

Foreign Key (ON DELETE CASCADE)

Look at this:

create TABLE BGW.YYY (
    ID number not null,
    PARENT_ID number not null references XXX(ID),
    PASSWORD varchar2(254) null
) TABLESPACE SSS;

Is it the same as the following two DDL?

create TABLE BGW.YYY (
    ID number not null,
    PARENT_ID number not null,
    PASSWORD varchar2(254) null
) TABLESPACE SSS;

ALTER TABLE BGW.YYY ADD (
    CONSTRAINT FK_YYY FOREIGN KEY (PARENT_ID)
    REFERENCES BGW.XXX (ID)
);

Do I need to add ON DELETE CASCADE to the ALTER TABLE statement to make it equivalent to the first CREATE TABLE statement?
0
yongsing
Asked:
yongsing
1 Solution
 
plamen73Commented:
yes, they are equivalent;
In order to make it on delete cascade you have to:
1. option 1 - one statement:
create TABLE BGW.YYY (
   ID number not null,
   PARENT_ID number not null references XXX(ID) ON DELETE CASCADE,
   PASSWORD varchar2(254) null
) TABLESPACE SSS;

2. option 2 - two statements:
create TABLE BGW.YYY (
   ID number not null,
   PARENT_ID number not null,
   PASSWORD varchar2(254) null
) TABLESPACE SSS;

ALTER TABLE BGW.YYY ADD (
   CONSTRAINT FK_YYY FOREIGN KEY (PARENT_ID)
    REFERENCES BGW.XXX (ID) ON DELETE CASCADE
);
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now