?
Solved

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

Posted on 2014-10-15
2
Medium Priority
?
798 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 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

764 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