Solved

PL/SQL: ORA-02266 with truncate, but with DELETE; it is OK... why?

Posted on 2014-10-15
2
722 Views
Last Modified: 2014-10-15
Hi experts:

i have this error
02266, 00000, "unique/primary keys in table referenced by enabled foreign keys"
when try: TRUNCATE TABLE ta_cuenta_contable;

i solution with
DELETE FROM ta_cuenta_contable;
    COMMIT;  

why?
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 40382140
The docs are your friend:
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10007.htm

Restrictions on Truncating Tables This statement is subject to the following restrictions:

•You cannot truncate the parent table of an enabled foreign key constraint. You must disable the constraint before truncating the table. An exception is that you can truncate the table if the integrity constraint is self-referential.
0
 
LVL 22

Accepted Solution

by:
Steve Wales earned 250 total points
ID: 40382141
It's the way Oracle implements truncate.

Refer to the Online Documentation: http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_10007.htm#SQLRF01707

Notably; You cannot truncate the parent table of an enabled foreign key constraint. You must disable the constraint before truncating the table.

Even if the enabled foreign key constraint has no data it's referencing, because of the way truncate works, it just won't let you do it - where as the delete will work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question