Truncate dangers SQL

 
create table is_a_very_quick_way ( col integer );

create procedure to_upset_all_your_users as begin null; end; 
/

create procedure when_they_find_the_table_empty as begin null; end; 
/

create procedure with_no_easy_recovery_method as begin null; end; 
/

--put some data in so we see what happens
insert into is_a_very_quick_way
  select rownum from dual connect by level <= 100;
  
select * from is_a_very_quick_way;

begin 
  dbms_utility.exec_ddl_statement(' truncate table is_a_very_quick_way '); 
  to_upset_all_your_users; 
  when_they_find_the_table_empty; 
  with_no_easy_recovery_method; 
end; 
/

--all our data is gone
select * from is_a_very_quick_way;

--even after we rollback
rollback;

select * from is_a_very_quick_way;

drop table is_a_very_quick_way purge; 
drop procedure to_upset_all_your_users; 
drop procedure when_they_find_the_table_empty ; 
drop procedure with_no_easy_recovery_method;

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)