简体   繁体   中英

MySQL: three tables related to each other

I am designing a database to store software testing data. The basic idea is the following: I want to store the information of each tested configuration, each tested software version and each found fault.

An example of a query I'd like to execute would be the following. I want to find all faults that were found on a specific configuration with a specific software.

My question is related to the table design, more specifically the relationships between them. Would this kind of design work in my case:

design

Or would it be better if the table "fault" was directly related to table "configuration"?

Thanks in advance.

Well, yes, it would be better to link directly "fault" to "configuration" as configuration_id should be a foreign key of "configuration.configuration_id" (the primary key). But, if there is only one "configuration" for each "software", then, since you already referenced "software_id" into "fault" table, you don't need to add "configuration_id" into "fault" as it is already present into "software" table.

You will retrieve all your data by this query:

SELECT * FROM fault INNER JOIN software ON fault.software_id = software.software_id INNER JOIN configuration ON software.configuration_id = configuration.configuration_id

Then, just remove "configuration_id" from "fault" table.

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