Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Truncate not working on Primary table

888025Nov 6 2013 — edited Nov 7 2013

Hi, I have the following tables

CREATE TABLE supplier1
( supplier_id number(10) not null,
  supplier_name varchar2(50) not null,
  contact_name VARCHAR2(50),
  CONSTRAINT supplier_pk1 PRIMARY KEY (supplier_id)
);

CREATE TABLE products1
( product_id number(10) not null,
  supplier_id NUMber(10) NOT NULL,
  CONSTRAINT fk_supplier1
    FOREIGN KEY (supplier_id)
    REFERENCES supplier1(supplier_id)
    ON DELETE CASCADE
);
insert into supplier1 values(1,'abc','bc');

insert into products1 values(2,1);

truncate table products1  -- I am able to truncate

truncate table supplier1 -- getting the below error

Error starting at line 22 in command:

TRUNCATE TABLE supplier1

Error report:

SQL Error: ORA-02266: unique/primary keys in table referenced by enabled foreign keys

02266. 00000 -  "unique/primary keys in table referenced by enabled foreign keys"

*Cause:    An attempt was made to truncate a table with unique or

           primary keys referenced by foreign keys enabled in another table.

           Other operations not allowed are dropping/truncating a partition of a

           partitioned table or an ALTER TABLE EXCHANGE PARTITION.

*Action:   Before performing the above operations the table, disable 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";

Can some one please tell me how to use truncate in this situation.

How to use truncate in such situations, Is there a different way to do?

Thanks in advance..

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2013
Added on Nov 6 2013
20 comments
3,990 views