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

From Boget, Chris
Subject Constraints/On Delete...
Date
Msg-id 4040BBE81A9AD411BD27009027887A7C0431C9@tiger.wild.net
Whole thread Raw
Responses Re: Constraints/On Delete...
List pgsql-general

Newbie alert!! :p

I have 2 tables already created

CREATE TABLE "first" (
"name" varchar (100) NOT NULL,
"record_num" SERIAL,
PRIMARY KEY ("record_num"));

CREATE TABLE "second" (
"text" varchar (10) NOT NULL,
"name" int4 REFERENCES "first"("record_num") NOT NULL,
"record_num" SERIAL ,
PRIMARY KEY ("record_num"));

and have records in each.  The "name" field in the "second"
table contains data that matches data in the "first".  Now,
when I go to delete a row from "first", I'm getting the error:

ERROR: $1 referential integrity violation - key in first still referenced from second

which I can understand.  Now, how can I alter the "first" table
so that when I delete rows from it, the corresponding rows from
the "second" table are deleted as well?  I was looking at the
ALTER TABLE syntax but the only thing I saw there was adding a
foreign key.  But I already have a foreign key set up by the
REFERENCES in the create definition for the "second" table, yes?
So what do I need to do?

thnx,
Chris

pgsql-general by date:

Previous
From: am@fx.ro
Date:
Subject: Re: postmaster.pid
Next
From: Tom Lane
Date:
Subject: Re: select for update with left outer joins?