FW: Foreign keys
От | Benjamin Jury |
---|---|
Тема | FW: Foreign keys |
Дата | |
Msg-id | 24DC688F52AAD611B60900096BB0B440015D82BA@chapar.mpuk.com обсуждение исходный текст |
Список | pgsql-general |
> I have foreign keys set up so that if, for example, a record > in customer > is deleted, the corresponding records in the customer_addresses table > are also removed. However, I can't find a way of ensuring > records in the > address table are deleted too, given that lots of different > tables will > reference address.id. > > What I'd like is for records in the address table to be automatically > deleted at the end of each transaction if nothing references them any > more. Is there any way to achieve this? You could set up a function which returns how many references a specific address has (or even better simply if it has any other references). Then using a trigger or another function to delete customers, suppliers etc could use the first function to find out if it can delete the original address. Ps: Must remember to reply to list not just the original poster! Doh!
В списке pgsql-general по дате отправления: