简体   繁体   中英

phpmyadmin foreign key problems

here's my situation: I have this 3 tables:

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).

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. 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. 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. But in you case you don't need that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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