Subject RE: [firebird-support] Optional FK constraint on 0 (not NULL)
Author Omacht András
Hi Bhavbhuti,

I can suggest you only a workaround….

1. your current field name is: MASTER_ID
2. add a new field, e.g.: MASTER_ID_FK
3. create a before insert and update trigger which fill up this field like this: new.master_id_fk = nullif(master_id, 0);
4. create the foreign key on MASTER_ID_FK field.


From: []
Sent: Wednesday, March 28, 2018 8:54 AM
Subject: [firebird-support] Optional FK constraint on 0 (not NULL)

Hi all

I have a transaction table that has an integer FK field. This FK field can be either a 0 (no master record selected) or an integer that is a FK value from the master PKs. If I put in a FK Constraint then it will not allow me a 0 in the transaction table's FK field. I know NULL is allowed but for the present I can't use NULL in the transaction table's FK field as it might impact other operations.

Is there an intermediate way to constraint only if a value > 0 is present in the transaction table's FK field. I need to stop a master record from deleting in case there is a reference.

Please advise

Kind regards


__________ Information from ESET Mail Security, version of virus signature database 17128 (20180328) __________

The message was checked by ESET Mail Security.

[Non-text portions of this message have been removed]