简体   繁体   English

phpmyadmin外键问题

[英]phpmyadmin foreign key problems

here's my situation: I have this 3 tables: 这是我的情况:我有这3张桌子:

Material(commercial_name,family,composition) (commercial_name is PK) Chemical(commercial_name,CAS) (commercial_name is PK) Compatibility_test(Chemical,Material,result) (Chemical and Material are foreign keys and refers to the PKs of the previous table). 材料(商业名称,家族,组成)(商业名称为PK)化学(商业名称,CAS)(商业名称为PK)兼容性测试(化学,材料,结果)(化学和材料为外键,指的是上表的PK)。

EXAMPLE

I have these materials M1,M2,M3 I have these chemicals C1,C2,C3 Now no problem if i wanna instert a test of C3 on M2 or any other combinations with those elements. 我有这些材料M1,M2,M3我有这些化学药品C1,C2,C3现在,如果我想在M2上插入C3的测试或与这些元素的任何其他组合,都没有问题。 But if i do a test with a new C4 chemical on for example M2 , that is not allowed cause C4 is not in the Chemicals table yet. 但是,如果我对新的C4化学品(例如M2)进行了测试,那是不允许的,因为C4不在“化学品”表中。 The question is: Is there a way to insert a test and if the elements of that test are not already in the Materials and Chemicals table they gonna be added , otherwise non changes to those table will be made? 问题是:是否可以插入测试,并且如果该测试的元素尚未在“材料和化学”表中添加,则可以添加它们,否则将不对那些表进行任何更改?

Thank you in advance 先感谢您

The only way to do that by removing the relations between these tables. 删除这些表之间的关系的唯一方法。 And already in like these cases 'by logic' you don't need these relations. 在这种情况下,“按逻辑”已经不需要这些关系。 Relation to link to table with each other, when you delete 1 row you may delete the related rows or you forbidden deletion if there are related rows and so on. 链接到表的关系,当您删除1行时,您可以删除相关行,或者如果有相关行,则禁止删除。 But in you case you don't need that. 但是,如果您不需要的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM