Unable to Drop an interim table after Redefinition Process (merged 3) [message #554171] |
Fri, 11 May 2012 02:13  |
 |
User653
Messages: 6 Registered: May 2012
|
Junior Member |
|
|
Hi Guys ,
I performed the Table Redefinition process on one of my transaction tables.
I wanted to redefine the existing table to a new table with partitions.
Everything worked fine until i reached the last step where we had to drop the interim table. Now in between the redefinition , we created the interim table with partition along with the constraints and indexes and then atlast ran the "dbms_redefinition.finish_redef_table" proc to finish the redefinition.
And after that when I tried to drop the interim table , I am getting the below error message
"ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys"
So this means all the constraints from my actual table were swapped with the interim table and hence I am getting this error.
So is this a normal case or I have missed something while performing the redefinition?
If thats normal then should i Just Drop table tablename CASCADE CONSTRAINTS?
|
|
|
|
|
|
|
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554187 is a reply to message #554171] |
Fri, 11 May 2012 04:08   |
 |
User653
Messages: 6 Registered: May 2012
|
Junior Member |
|
|
Hi John ,
Thanks for the help.
Could you please let me know that if we are expected to get the above error message while we are trying the drop the interim table?
I have completed the redefinition process and now I just need to drop the interim table.
I am getting the above error message when I try to drop the interim table.
So should I just drop the interim table using the below statement?
---------------------------------------------------------------------------------[code]
DROP TABLE TABLENAME CASCADE CONSTRAINTS
----------------------------------------------------------------------------------
[Updated on: Fri, 11 May 2012 04:12] Report message to a moderator
|
|
|
|
|
|
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554268 is a reply to message #554204] |
Fri, 11 May 2012 12:49   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
User653 wrote on Fri, 11 May 2012 03:39
So should I drop the interim table by using the Cascade Constraints option or that is not an ideal way of doing that?
Yes, you should drop the interim table using CASCADE CONSTRAINTS. Please see the demonstration below.
SCOTT@orcl_11gR2> -- starting tables, data, and constraints:
SCOTT@orcl_11gR2> CREATE TABLE transaction_table
2 (transaction_column NUMBER,
3 CONSTRAINT transaction_pk PRIMARY KEY (transaction_column))
4 /
Table created.
SCOTT@orcl_11gR2> INSERT INTO transaction_table (transaction_column)
2 SELECT deptno FROM dept
3 /
4 rows created.
SCOTT@orcl_11gR2> CREATE TABLE child_table
2 (child_col NUMBER,
3 CONSTRAINT child_fk FOREIGN KEY (child_col)
4 REFERENCES transaction_table (transaction_column))
5 /
Table created.
SCOTT@orcl_11gR2> INSERT INTO child_table
2 SELECT deptno FROM emp
3 /
14 rows created.
SCOTT@orcl_11gR2> -- interim table:
SCOTT@orcl_11gR2> CREATE TABLE interim_table
2 (transaction_column NUMBER)
3 PARTITION BY RANGE (transaction_column)
4 (PARTITION part1 VALUES LESS THAN (21),
5 PARTITION partm VALUES LESS THAN (MAXVALUE))
6 /
Table created.
SCOTT@orcl_11gR2> -- redefinition:
SCOTT@orcl_11gR2> DECLARE
2 v_num_errors NUMBER;
3 BEGIN
4 DBMS_REDEFINITION.CAN_REDEF_TABLE
5 (USER,
6 'TRANSACTION_TABLE');
7 DBMS_REDEFINITION.START_REDEF_TABLE
8 (USER,
9 'TRANSACTION_TABLE',
10 'INTERIM_TABLE');
11 DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS
12 (USER,
13 'TRANSACTION_TABLE',
14 'INTERIM_TABLE',
15 NUM_ERRORS => v_num_errors);
16 DBMS_REDEFINITION.FINISH_REDEF_TABLE
17 (USER,
18 'TRANSACTION_TABLE',
19 'INTERIM_TABLE');
20 DBMS_OUTPUT.PUT_LINE ('errors: ' || v_num_errors);
21 END;
22 /
errors: 0
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> -- attempt to drop interim table fails without cascade constraints:
SCOTT@orcl_11gR2> DROP TABLE interim_table
2 /
DROP TABLE interim_table
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
SCOTT@orcl_11gR2> -- dropping interim table is successful with cascade constraints:
SCOTT@orcl_11gR2> DROP TABLE interim_table CASCADE CONSTRAINTS
2 /
Table dropped.
SCOTT@orcl_11gR2> -- table is now partitioned:
SCOTT@orcl_11gR2> SELECT * FROM transaction_table PARTITION (part1)
2 /
TRANSACTION_COLUMN
------------------
10
20
2 rows selected.
SCOTT@orcl_11gR2> SELECT * FROM transaction_table PARTITION (partm)
2 /
TRANSACTION_COLUMN
------------------
30
40
2 rows selected.
SCOTT@orcl_11gR2> -- primary key constraint is still in effect:
SCOTT@orcl_11gR2> INSERT INTO transaction_table (transaction_column) VALUES (20)
2 /
INSERT INTO transaction_table (transaction_column) VALUES (20)
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.TRANSACTION_PK) violated
SCOTT@orcl_11gR2> -- foreign key on child table is still in effect:
SCOTT@orcl_11gR2> INSERT INTO child_table (child_col) VALUES (21)
2 /
INSERT INTO child_table (child_col) VALUES (21)
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.CHILD_FK) violated - parent key not
found
|
|
|
|