I am currently testing out something, and encountering an issue when trying to insert some values in a table.
I have 3 tables as following; Devices, Outdoor, indoor.
**outdoor** ---> **devices** <----- **indoor**
net_id(pk) net_id(fk) net_id(pk)
I wanted to have a relationship so that a device can be either outdoor or indoor, by having either the net_id of indoor or outdoor. Thus I did the following:
ALTER TABLE devices
ADD CONSTRAINT o_relationship
FOREIGN KEY (net_id)
REFERENCES outdoor (net_id);
ALTER TABLE devices
ADD CONSTRAINT i_relationship
FOREIGN KEY (net_id)
REFERENCES indoor (net_id);
Now my problem is, when i am trying to insert a value in devices, i am unable to do so unless the net_id values belongs to both indoor and outdoor table. This means that let's say "net_001" exists in indoor and outdoor table it allows me to insert it in devices, but if "net_001"exists in indoor and "net_002" exists in outdoor and let's say I want to add "net_001" or "net_002" in devices it won't allow me to do so. Thus I want to be able to do insertion in devices table that as explained above.
Hope i was clear enough to explain the issue. Thank you in advance!