mysql - Insert issue on foreign key column -
I am currently testing something and facing a problem while trying to enter some value in a table I am
I have 3 tables; Equipment, Outdoor, Indoor
** External ** -> ** Device ** & lt; ----- ** 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 , Either through indoor or outdoor net_id.
change table devices o_relationship foreign key (net_id) add static point reference external (net_id) reference: I did the following: Add optional table device contract i_relationship foreign key (net_id) reference indoor (net_id) ; Now my problem is, when I'm trying to insert a value in the devices, I am unable to do this as long as the net_id value is not both from the indoor and outdoor tables. Ho. It is assumed that this means "net_001" is present in the indoor and outdoor tables, allowing it to be inserted into my devices, but if "net_001" is present in the indoor and "net_002" is present in the outdoor and suppose I want to add "net_001" or "let's go to Net_002" in this device will not allow me to do this, thus I want to be able to merge into the device table, as explained above.
Hope I was enough to clarify this problem. Thank you in advance!
Maintain a relation table between the devices and & amp; Device out
Solution 1 :. Device_Relation table for
+ - ---------------- + --- ----------- + | Of table | Column | + ------------------ + -------------- + | | Indoor | Net_ID | - & lt; --- PK | Outdoor | Net_ID | - & lt; --- PK | Tools | Device_id | - & lt; --- PK | Device_relationships | D.device_id, | - & lt; --- PK | | od.net_id, | - & lt; --- fk | | id.net_id | - & lt; --- fk + ------------------ + -------------- + Resolution 2 : In_Out_Relation table for <-> - -------- - + -------------- + | Of table | Column | + ------------------ + -------------- + | | Indoor | Net_ID | - & lt; --- fk | Outdoor | Net_ID | - & lt; --- fk | In_out_id | in_out_id | - & lt; --- PK + ------------------ + -------------- + Tools Table For ------------------ + ------ --- ----- + | Of the table | Column | + ------------------ + -------------- + | | Tools | Device_ID | - & lt; --- PK | In_Out_Relation | Io.in_out_id | - & lt; --- fk + ------------------ + -------------- +
Comments
Post a Comment