FW: Foreign keys

Started by Benjamin Juryalmost 23 years ago1 messagesgeneral
Jump to latest
#1Benjamin Jury
benjamin.jury@mpuk.com

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!