mysql - Is it better to have a table with an upwards of 30 similar attributes or should I make a new table? -


i'm relatively new database design. i've taken couple classes on it, i'm still not confident. i'd appreciate design!

i'm creating database of cosmetics (like face mosturizer, hand lotion, etc.). boring, know. that's i'm doing. basically, important part of able query ingredients. i.e. find creams contain zinc oxide, find creams have shea butter , not coconut. now, i'm not sure how should design tables. there many ingredients going using (around 100 or 200). thinking would make boolean each ingredient in cream table. true if has it, false if not. pretty excessive, since attributes turn out false. thought maybe try separate ingredients types , have table have multivalued attributes. i.e. possible design:

table cosmetic:

ingredients_with_spf

animal_sourced

plant_sourced

...

this might seemed bit forced group them this, usage quite useful types of queries want make (overlap not huge issue)

another idea have take idea of grouping them , make table each type of ingredient.

what faster method? more intuitive, in case want have me project?

on assumption answer above question yes, suggest following tables...

cosmetic

cosmeticid       pk cosmeticname     req cosmetictypeid   fk 

note : cosmeticid table's primary key (aka unique identifier). cosmetictype foreign key, i.e. can use refer type of cosmetic. cosmeticname required (aka not null) field. other fields can added peculiar cosmetic opposed 1 of other tables.

cosmetic type

cosmetictypeid     pk cosmetictypename   req 

this table used store various types of cosmetic (hand sanitiser, face moisturiser, etc.). assuming cosmetic can 1 of these types here. please if can more 1 of these types.

ingredient

ingredientid      pk ingredientname    req otherattribute1   opt 

for storing of details peculiar ingredient.

cosmeticingredient

cosmeticid       pk & fk ingredientid     pk & fk otherattribute   opt 

the combination of cosmeticid , ingredientid can used track if ingredient being used in cosmetic. other details can stored, such concentration, etc.

ingredientattribute

ingredientattributeid   pk description             req 

this table can used store details peculiar ingredient attribute (such plant sourced, animal sourced, has spf, etc.

ingredientingredientattribute

ingredientattributeid   pk & fk ingredientid            pk & fk otherdetails            opt 

this table can used track if ingredient has attribute (and details associated combination).

the above may seem alot of tables, once used database design begin appreciate how can track remarkable variety of combinations of data.

if have questions or comments, please feel free post them.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -