I’m a beginner in SQL and would like to make sure I’m approaching the proper architecture design for a database I’m creating.
I’ve come up with a simpler example of my overall design.
Say I have a table:
mysql> create table Animals(name varchar(255), flags int);
where flags holds truth values for properties of an animal, such as Carnivore, Amphibian, Mammal, et cetera.
Since int is just a binary number, I could could use XOR to filter through these flags for what I want matched.
Or I could have a table like this:
mysql> create table Animals(name varchar(255), flag1 bit, flag2 bit, flag3 bit);
My concern for this is:
Are bits wasted using this approach, or if I have flag1 – flag8, one byte will be used?
Ultimately:
Is this even an appropriate way to go about doing this sort of design? If not, some guidance would really be appreciated.
I understand that I could have a ton of tables for say, Carnivore, Amphibian, Mammal, et cetera, which would have entries with the same names at mammals, which would avoid my want to use flags, but that almost seems wasteful to me.
To properly normalize, you need to create another table:
This will allow you to have as many or as few flags per animal as you want without the mess of having to parse with XOR.