Useful shortcuts for vi editor

Showing posts with label ORA-02449. Show all posts
Showing posts with label ORA-02449. Show all posts

Wednesday 11 April 2018

ORA-02449 solution

Preparation
SQL>
CREATE TABLESPACE EXAMPLE_TS DATAFILE
  'C:\ORACLEXE_XE\APP\ORACLE\ORADATA\XE\example_01.dbf' SIZE 512K REUSE
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

SQL>
CREATE TABLESPACE EXAMPLE_TS_2 DATAFILE
  'C:\ORACLEXE_XE\APP\ORACLE\ORADATA\XE\example_02.dbf' SIZE 512K REUSE
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

SQL>
CREATE TABLE T_EXAMPLE (ID NUMBER)
TABLESPACE EXAMPLE_TS;

SQL>
CREATE TABLE T_EXAMPLE_CHILD (ID NUMBER, FID NUMBER)
TABLESPACE EXAMPLE_TS_2;

SQL>
ALTER TABLE T_EXAMPLE
ADD CONSTRAINT ID_EXAMPLE_PK
PRIMARY KEY (ID);

SQL>
ALTER TABLE T_EXAMPLE_CHILD
ADD CONSTRAINT FID_EXAMPLE_FK
FOREIGN KEY (FID)
REFERENCES T_EXAMPLE (ID);

Action
SQL>
DROP TABLESPACE EXAMPLE_TS;

Error
ORA-01549: tablespace not empty, use INCLUDING CONTENTS option

Next Action
SQL>
DROP TABLESPACE EXAMPLE_TS INCLUDING CONTENTS AND DATAFILES;

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

Solid Solution
SQL>
DROP TABLESPACE EXAMPLE_TS INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;

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.