ON DELETE CASCADE and TRIGGER

From: Raymond Chui <raymond(dot)chui(at)noaa(dot)gov>
To: pgsql-general(at)postgresql(dot)org
Subject: ON DELETE CASCADE and TRIGGER
Date: 2001-01-31 19:50:37
Message-ID: 3A786C8D.FE564C8A@noaa.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have three tables:

CREATE TABLE table1 (
id char(8) NOT NULL,
....
PRIMARY KEY (id)
);

CREATE TABLE table2 (
id char(8) NOT NULL,
....
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES table1 (id) ON DELETE CASCADE
);

CREATE TABLE table3 (
id char(8) NOT NULL,
code char(2) NOT NULL,
orders integer NOT NULL,
....
PRIMARY KEY (id,code,orders),
FOREIGN KEY (id) REFERENCES table2 (id) ON DELETE CASCADE
);

Now you can see I must insert a row in table1 1st, then insert a row in
table2,
then insert the rowS in table3. That is OK

Now I want to delete an id in all three tables. How can I delete a row
in table1
trigger to delete rows in table2, table3? Since I can't put "ON DELETE
CASCADE"
for PRIMARY KEY in table1.
Now I can only delete a row in table2 which trigger to delete rowS in
table3.
If I want to

CREATE TRIGGER BEFORE DELETE ON table1 FOR EACH ROW
EXECUTE PROCEDURE table1_trigger(arg);

What I suppose pass to the arg in table1_trigger()?

Thank you very much in advance!

--
Why we want to teach our babies to talk and walk,
then later we tell them "sit down!", "be quiet!" ?

Democracy is not a better way for a solution,
it is just another way to spread the blames.

--Raymond

Attachment Content-Type Size
raymond.chui.vcf text/x-vcard 421 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adam Lang 2001-01-31 19:58:23 Re: Re: php as stored procedures
Previous Message Martin A. Marques 2001-01-31 19:41:59 Re: Re: grant privileges to a database