Constraint Question - Mailing list pgsql-general

From Kai Hessing
Subject Constraint Question
Date
Msg-id 47tki5Fh5nsuU1@individual.net
Whole thread Raw
Responses Re: Constraint Question  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
Hi Folks,

I'm not perfekt in SQL so I'm not really sure, how this can be done.

I have a master table stud containing (amongs others) two rows called
'sid' and 'status'. Now I have different tables using constraints to
reference this table. For example I have one table called phon with the
rows 'phonid', 'sid' and 'status'. 'sid' is currently the Foreign Key
and the Entry in Phone is updated oder deleted, when the sid in the
master table is. So far so good.

The 'status'-row can contain either 1 or -1 and -4. And now I would like
to implement the action that if the the status field in the master table
for a special sid is changed, all status-fields in phon for entries
which referencing this sid are also changed.

Can this be done somehow with a foreign key? If it can, how?

Else I think it could be done about a trigger that is set in the
mastertable for setup. The problem is, the Trigger must be updated
everytime a new table is added, that references the master table. Or is
it possible to write a Trigger for the phon-table that checks the status
field from stud everytime it is updated, so I can implement additional
functionality (somewhat like ' if (phon.status=1 or phon.status=-1) and
(stud.status is updated) then phon.status=stud.status ' )?

Thanks and *greets*
Kai...

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dumpall: permission denied for relation pg_shadow
Next
From: "Ing. Claudio Roberto Seu"
Date:
Subject: pregunta de principiante