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 all tables within schema with FK contraint enabled

Rajneesh S-OracleJun 15 2020 — edited Jun 16 2020

Hello All,

I am using below script to truncate all tables within schemas in DB:

begin
for r in
(
select owner,table_name from all_tables where owner in
(
'TRX',
'DWH'
)
)
loop
execute immediate 'truncate table ' || r.owner||'.'||r.table_name;
end loop;
end;

How ever this script will fail if tables are having referential integrity (FK constraint).

Any suggestion to truncate tables with FK constraint enabled (like cascade delete etc)?

Thanks,

Rajneesh

This post has been answered by Solomon Yakobson on Jun 16 2020
Jump to Answer
Comments
Post Details
Added on Jun 15 2020
11 comments
3,760 views