Subject Re: [firebird-support] row reference count
Author Helen Borrie
At 12:00 PM 18/11/2003 +0000, you wrote:
>how to check, is row referenced in other tables via FK? I have
>master-detail relation, so when I delete detail row, master row is
>deleted also (set cascade on).

That's not what the cascade delete does. It should delete *detail* rows if
the master is deleted but it won't won't delete the master row if details
are deleted. You would have to add your own triggers to make that happen.

>In most cases this is ok, but sometimes
>need to check, is any reference to erasable row - some tables may be
>locked for changes, so cascading delete would destroy important data

If the rows were locked, your transaction could not delete them. That's
what transaction isolation is for.


>Another question:
>if I execute such delete code:
>delete from table where "Name"="John";
>how in trigger to check, that matching row (say, that PK is "Row_ID"
>column) is referenced in other tables via FK?

The engine does that automatically.

h.