Magically removing your data SQL

 
create table so_ditch_them_for_me (by_making_the_relationship integer primary key);
create table im_too_damn_lazy (when_removing_the_parents integer primary key);

alter table    im_too_damn_lazy 
add constraint to_manually_destroy_the_kids 
foreign key   (when_removing_the_parents) 
references     so_ditch_them_for_me (by_making_the_relationship) 
on delete cascade;


--put some data in
insert into so_ditch_them_for_me
  select rownum from dual connect by level <= 2;

insert into im_too_damn_lazy
  select * from so_ditch_them_for_me;

commit;
  
--now you see them
select * from im_too_damn_lazy;

--delete from the parent
delete from so_ditch_them_for_me;

--now you don't
select * from im_too_damn_lazy;
--both handy and dangerous at the same time...

drop table im_too_damn_lazy purge;
drop table so_ditch_them_for_me purge;

 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)