Home » SQL & PL/SQL » SQL & PL/SQL » Unable to Drop an interim table after Redefinition Process (merged 3) (Oracle 10.2.0.4.0 , Windows 7)
Unable to Drop an interim table after Redefinition Process (merged 3) [message #554171] Fri, 11 May 2012 02:13 Go to next message
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 #554177 is a reply to message #554171] Fri, 11 May 2012 02:53 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

ORA-02449:
	unique/primary keys in table referenced by foreign keys
Cause: 	An attempt was made to drop a table with unique or primary keys referenced by foreign keys in another table.
Action: Before performing the above operations the table,
 drop the foreign key constraints in other tables. 
You can see what constraints are referencing a table by issuing the following command: 
SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = "tabnam";
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554178 is a reply to message #554177] Fri, 11 May 2012 02:54 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Or else go to this site

http://www.techonthenet.com/oracle/errors/ora02449.php
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554180 is a reply to message #554178] Fri, 11 May 2012 03:16 Go to previous messageGo to next message
User653
Messages: 6
Registered: May 2012
Junior Member
Thanks for the infor muralikri.

I do know how to check for constraints but my issue is mainly related to the Redefinition process.
basically i should not have got this error after my redefinition process.
But still I am getting it.

So that was my question that is it normal to get such error after redefinition or i have done the redefinition incorrectly.

Should I go ahead and drop the INTERIM TABLE created during the redefinition process or perform some other step to avoid this issue?
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554181 is a reply to message #554171] Fri, 11 May 2012 03:47 Go to previous messageGo to next message
John Watson
Messages: 8978
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum. Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read

You should drop your interim table, and all dependent objects. If you think about what dbms_redefinition does, it becomes clear: the rows are copied from the original table to the interim table, and then the two tables are renamed. So what was your original table (and all its constraints) now has the name of the interim table, and vice versa. You can see this if you check the object_ids of the tables before and after executing dbms_redefinition.finish_redef_table. You have to rename te constraints and indexes yourself.
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 Go to previous messageGo to next message
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 #554201 is a reply to message #554187] Fri, 11 May 2012 05:27 Go to previous messageGo to next message
User653
Messages: 6
Registered: May 2012
Junior Member
Hi All,

Could you please help me in getting this resolved as I am very much stuck here?
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554203 is a reply to message #554201] Fri, 11 May 2012 05:33 Go to previous messageGo to next message
John Watson
Messages: 8978
Registered: January 2010
Location: Global Village
Senior Member
Quote:
You should drop your interim table, and all dependent objects.
Sorry, but I don't know what more I can say.
Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554204 is a reply to message #554203] Fri, 11 May 2012 05:39 Go to previous messageGo to next message
User653
Messages: 6
Registered: May 2012
Junior Member
Hi John ,

Thanks for the info.

But i Cant drop the dependent objects as they are needed in the application. And those dependent objects are also referring the actual table which has been redefined.

So should I drop the interim table by using the Cascade Constraints option or that is not an ideal way of doing that?
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 Go to previous messageGo to next message
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

Re: Unable to Drop an interim table after Redefinition Process (merged 3) [message #554293 is a reply to message #554171] Sat, 12 May 2012 02:06 Go to previous message
User653
Messages: 6
Registered: May 2012
Junior Member
Hi Barabara ,

Thank you so much for the help.

Thanks for pasting the example as it really proved to be very helpful.

Thanks everyone for your help.
Previous Topic: sql & syntax (regex maybe) (4 threads merged by bb)
Next Topic: .exists syntax
Goto Forum:
  


Current Time: Mon Jun 09 23:58:06 CDT 2025