Re: cascade delete

From: Andrew Rawnsley <ronz(at)ravensfield(dot)com>
To: Bhushan Bhangale <bbhangale(at)Lastminute(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: cascade delete
Date: 2004-02-16 15:58:11
Message-ID: EBDDFADC-6098-11D8-BD8B-000393A47FCC@ravensfield.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc


If I am understanding properly what you want, you have your
referential integrity backwards.
If you want everything from table image to be removed when you execute
'delete from accomm_images' your
table definition should be:

> CREATE TABLE accomm_images(
> accomm_id int4 NOT NULL references accomm(id),
> image_id int4 NOT NULL
> );

> CREATE TABLE image(
> id int4 NOT NULL references accomm_images(image_id) on
> delete cascade,
> url int4 NOT NULL
> );

The reference goes from child to parent, not parent to child, and from
what you say the image table is the child
and accomm_images is the parent.

On Feb 16, 2004, at 9:49 AM, Bhushan Bhangale wrote:

> Hi,
>
> I have following 2 tables in postgres DB. I created a cascade delete
> constraint on image_id column of accomm_images which is a foreign key
> from
> image tbale.
>
> When I execute -> delete from accomm_images
> It should delete all the child records of image table as well. But its
> not
> happening.
>
> CREATE TABLE image(
> id int4 NOT NULL,
> url int4 NOT NULL
> );
>
> CREATE TABLE accomm_images(
> accomm_id int4 NOT NULL references accomm(id),
> image_id int4 NOT NULL references image(id) on delete
> cascade
> );
>
>
> Is there anything missing?
>
> Thanks
> Bhushan
>
> _______________________________________________________________________
> _
> This e-mail has been scanned for all viruses by Star Internet. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> _______________________________________________________________________
> _
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 8: explain analyze is your friend
>
--------------------

Andrew Rawnsley
President
The Ravensfield Digital Resource Group, Ltd.
(740) 587-0114
www.ravensfield.com

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bhushan Bhangale 2004-02-16 16:02:11 Re: cascade delete
Previous Message Bhushan Bhangale 2004-02-16 15:53:58 Re: cascade delete