Re: Constraints/On Delete... - Mailing list pgsql-general

From Boget, Chris
Subject Re: Constraints/On Delete...
Date
Msg-id 4040BBE81A9AD411BD27009027887A7C0431CA@tiger.wild.net
Whole thread Raw
In response to Constraints/On Delete...  ("Boget, Chris" <chris@wild.net>)
Responses Re: Constraints/On Delete...
List pgsql-general

> You don't alter first.  You need to drop the constraint on
> second and add a new constraint on second with on delete
> cascade.

Could you give me an example of this?  This is what I tried:

ALTER TABLE "second" ADD CONSTRAINT "secondfk"
FOREIGN KEY (record_num) REFERENCES "first"("record_num")
ON DELETE CASCADE

which gave me this error:

ERROR: secondfk referential integrity violation - key referenced
from second not found in first

What am I doing wrong?

Also, from the looks of it, it seems like what will happen is
when records from "second" are deleted, the referenced records
in "first" will be deleted, too.  Is this the case?  If so,
what I want to happen is that when records are deleted in the
"first table" (the root or parent table, if you will), records
will also be deleted in the "second" table.  Again, if so, how
do I go about setting this functionality up?

Chris

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Constraints/On Delete...
Next
From: Stephan Szabo
Date:
Subject: Re: Constraints/On Delete...