ON DELETE CASCADE
ON DELETE CASCADE
clause with a FOREIGN KEY
constraint tells that
when a row in the parent table is deleted, any matching rows in the child table are also deleted.
SQL> CREATE TABLE departments
2 (department_id number(10) primary key,
3 department_name varchar2(50) not null
4 );
Table created.
SQL>
SQL> CREATE TABLE employees
2 ( employee_id number(10) not null,
3 last_name varchar2(50) not null,
4 job_id varchar2(30),
5 salary number(6),
6 manager_id number(6)
7 );
Table created.
SQL>
SQL> ALTER TABLE employees
2 ADD CONSTRAINT by_fk
3 department_id REFERENCES departments(department_id) ON DELETE CASCADE;
Table altered.
SQL>
Home »
Oracle »
Table »
Oracle »
Table »
Constraints:
- Adding a Constraint with CHECK
- Adding a NOT NULL Constraint
- Adding a FOREIGN KEY Constraint
- ON DELETE CASCADE
- ON DELETE SET NULL
- Adding a UNIQUE Constraint
- CHECK constraint
- Multiple Constraints
- Dropping a Constraint
- Disabling a Constraint
- Enabling a Constraint
- Deferred Constraints
- Getting Information on Constraints:user_constraints and all_constraints
Related: