Subject Re: [firebird-support] Re: get foreign key
Author ian

Please do not take this the wrong way, but I think you need to do some
more thinking, before you do any more coding.

Rick Debay wrote:
> > if the user change the currency_id in the customer record then i have
> to change all the currency_id in sales order which reference to this
> customer

A completed transaction happened with a particular currency id. If the
customer then changes the currency, this will only affect future
transactions, not previous ones. Whether or not you allow customers to
change currency is a business decision, not a technical one.

> Cascading update on the foreign key.

This would change the details of completed transactions, to give invalid

> > i have to prevent the user from changing the currency id ones its been
> used in sales order

Only if you choose to restrict them to the first currency used.
> You're right. Deleting a record is a bad idea. however, i do need to
> know whether the current customer record have active foreign key
> references.

Test for records in the child table with something like this,
substituting your actual table/field names:

IF EXISTS (SELECT 1 FROM sales WHERE customer = id)