I'm trying to get the following scenario to work:
I have three tables, and one of them (IncidentDetail
) is to hold incident information of the other two (Incident
and PendIncident
). I want the IncidentDetail
table to reference either an incident in the Incident
, or PendIncident
table so it could exist in either place. How would I set up the constraints?
Table 1 - Incident
:
+--------------------+
| IncidentNbr | Desc |
+--------------------+
Table 2 - PendIncident
:
+------------------------+
| PendIncidentNbr | Desc |
+------------------------+
Table 3 - IncidentDetail
:
+-----------------------+
| IncidentNbr | Details |
+-----------------------+
The IncidentDetail
table will have a FK constraint so that the IncidentDetail.IncidentNbr
will need to have a value in either the Incident.IncidentNbr
column OR the PendIncident.PendIncidentNbr
column.
Is it possible to have a FK constraint on a single column that references into two different tables or will I need a second PendIncidentNbr
column in the IncidentDetail
table that has its own FK constraint to PendIncident.PendIncidentNbr
?
Is that enough to ensure that the IncidentDetail
table satisfies at least one of the FK constraints?
The other approach I can think of is to drop the FK constraints all together and use a check constraint where either the IncidentDetail.IncidentNbr
column or IncidentDetail.PendIncidentNbr
column has a value.