I'm pretty new to designing databases, and i'm encountering a challenge;
In a lab, DNA samples are prepared from tissue samples. These tissue samples have attributes such as species and location. It is possible, but not always the case, that different tissue samples are mixed before DNA sample preparation.
So, there are 3 tables, with following attributes:
A table, Tissue_sample
:
- ID
- location
- species
A table, Mixed_tissue_sample
:
- ID
- tissue samples which are mixed together
A table, DNA_sample
:
- ID
- tissue_sample OR mixed_tissue_sample
It should be possible to retrieve all tissue samples from which a DNA sample is prepared.
What is the most elegant way to fit this into a database? And is possible to do this in the MySQL workbench?
Define two fields in DNA table to reference a single or a mixed tissue sample. One of these fields will remain NULL.
tissue: id, location, species
mixed: id, ...
mixed_tissues: mixed_id, tissue_id
DNA: id, tissue_id, mixed_id
And yes, you can create these tables in MySQL workbench.
First, resolve the relation between Tissue_sample
and Mixed_tissue_sample
. 1 or more Tissue_sample defines a Mixed_tissue_sample, therefore the relation is 1:n and you need to have another column at Tissue_sample
, which will serve as a foreign key
to Mixed_tissue_sample
. You can get the tissue samples of a mixed tissue sample by joining the two tables upon the identified of Mixed_tissue_sample
.
Second, you need to resolve the DNA_sample
. You need a foreign key
to Tissue_sample
and to Mixed_tissue_sample
as well.
You can make sure a DNA_sample
has no connection to both by creating a trigger which will prevent any inserts
or updates
which would result in a record of DNA_sample
which has values for both foreign keys
if you need that.
Use table inheritance.
Either put tissue sample and mixed tissue sample all in the same table (single table inheritance), with a "type" column,
or put them in two different tables with their primary key pointing to a common table (class table inheritance). DNA sample table would point at this common 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.