Bruno Wolff III wrote: > On Thu, Mar 16, 2006 at 18:11:33 +0100, > Kai Hessing <kai.hessing@xxxxxxxxxx> wrote: >> >> 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? > > This seems kind of odd. If the values are supposed to be the same, why are > you including them in multiple tables? If there aren't supposed to always > be the same, you won't be able to use foreign keys to sometimes make them > the same. OK, it is really a little bit odd. I try to explain what should be done. I have 1:n connection between stud and phon (One student does have different phonenumbers, fax, eMails, etc...). A positive status means that the entry is active and a negative status means that the entry is inactive. So I have the possibility to set individual entries in phon to inactive while the corresponding entry in stud is still active. But if the entry in stud is set to inactive all corresponding entries in phon should also be set to inactive. I think I will put a Trigger on stud.status which updates the status of all connected tables. The only thing is, that the trigger must be updated every time I add a new table. So I like the idea of foreign keys which are doing it the reverse way and are set on the table which should be updated, and this table stays to be some sort of an independet module without the need of modifiing another table to update this one. But I think the trigger would be the only usable possibility. So I have to get a little bit used to triggers and their functions. Is it right, that the trigger event is fired each time an UPDATE on the table is executed, or can it be configured only to be fired if an UPDATE on the status-row is performed? I think for performance reasons it would definitly the better way. > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq Yeah, didn't found anything about it.