Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the software modeling world, this would obviously be done with a class for each species, I.E. "Dog", "Cat", "Fish" which extend "Animal". In the relational database world, this becomes a bit harder to represent.</p> <p>If you wanted to match this object-oriented approach in your database, you would have a table for "Animals" and then a table for each species, "Cat", "Dog", and "Fish". Then you would probably have a species table (or a hard-coded enum in your code) that would give you a value to place in the Animal row for which species each animal was. This would tell you how to look up further information for each animal.</p> <p>This is probably not the best approach. What you have is more what I would call "Custom Data" for each animal. You should define one table that has a list of custom attributes, and another table to match these attributes to a value for each animal row.</p> <p>If you'd like to make it more convenient to see and control which attributes can apply to which species you could make a third table for "Categories" which would link to the Animal species and to a collection of attributes. Then you would specify the category ID on the animal row.</p> <p>Sample tables:</p> <pre><code>Animals ------- ID Age Sex Species Breed Parameters ---------- ID Name Parameter Values ---------------- ParameterID AnimalID Value Categories (optional - add CategoryID to animals) --------------------- ID Name Category Parameters ------------------- CategoryID ParameterID </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload