Re: Delete child-parent records???????

From: Divya <traineensp_at_softcell.co.in>
Date: 24 Jun 2003 21:21:47 -0700
Message-ID: <c343a42.0306242021.391581c0_at_posting.google.com>


Hi Andrew,

Thanks for your help....

But there is a little issue here....these tables that have been created by someone else and I dont think Mr. X has used the words "on cascade delete" in his query while creating the child table....So can i still find a way to delete child-parent records?

Regards,
Divya

andrewst <member14183_at_dbforums.com> wrote in message news:<3036817.1056447364_at_dbforums.com>...
> Originally posted by Divya
> > Hi Tony,
> > Thanks for your help....
> >
> > For the ON DELETE CASCADE...Can you just show me a simple example to
> > explain this better?
> >
> >
> OK:-
>
> SQL> create table parent( parent_id number primary key, parent_name
> SQL> varchar2(10) );
>
> Table created.
>
> SQL> create table child( child_id number primary key, child_name
> SQL> varchar2(10),
> 2 parent_id number,
> 3 constraint child_parent_fk foreign key (parent_id)
> references parent
> 4 on delete cascade
> 5* );
>
> Table created.
>
> SQL> insert into parent values (1,'Fred');
>
> 1 row created.
>
> SQL> insert into parent values (2,'Barney');
>
> 1 row created.
>
> SQL> insert into child values (11,'Pebbles',1);
>
> 1 row created.
>
> SQL> insert into child values (21,'Bambam', 2);
>
> 1 row created.
>
> SQL> select * from parent;
>
> PARENT_ID PARENT_NAM
> ---------- ----------
> 1 Fred
> 2 Barney
>
> SQL> select * from child;
>
> CHILD_ID CHILD_NAME PARENT_ID
> ---------- ---------- ----------
> 11 Pebbles 1
> 21 Bambam 2
>
> SQL> delete parent where parent_id=2;
>
> 1 row deleted.
>
> SQL> select * from child;
>
> CHILD_ID CHILD_NAME PARENT_ID
> ---------- ---------- ----------
> 11 Pebbles 1
Received on Wed Jun 25 2003 - 06:21:47 CEST

Original text of this message