Useful shortcuts for vi editor

Showing posts with label cascade constranits. Show all posts
Showing posts with label cascade constranits. Show all posts

Friday 9 March 2018

ORA-02449 solution

Preparation
SQL>
-- A table is child table
create table A (id number, soid number);

SQL>
-- B table is parent table
create table B (id number); 

SQL>
alter table B
add constraint ID_B_PK 
primary key (id);

SQL>
alter table A
add constraint ID_A_PK 
primary key (id);

SQL>
alter table A
add constraint SOID_B_FK
foreign key (soid)
references B (id);

Action
SQL> 
drop table B;

Error
ORA-02449: unique/primary keys in table referenced by foreign keys

Solution
SQL>
drop table B cascade constraints;

Result
By "cascade constraints" keywords, only SOID_B_FK foreign key removed from Table A, ID_A_PK primary key remains for Table A.