Am I Properly Normalizing this Data

后端 未结 2 1455
时光取名叫无心
时光取名叫无心 2021-02-20 15:34

I am completing normalization exercises from the web to test my abilities to normalize data. This particular problem was found at: https://cs.senecac.on.ca/~dbs201/pages/Normali

2条回答
  •  渐次进展
    2021-02-20 15:47

    In a first step you could create the following tables (assuming pet_id is unique in the table):

    Pets:   pet_id, pet_name, pet_type, pet_age, owner
    Visits: pet_id, visit_date, procedure
    

    Going further you could split procedure since the description is repeating:

    Pets:       pet_id, pet_name, pet_type, pet_age, owner
    Visits:     pet_id, visit_date, procedure_id
    Procedures: procedure_id, description
    

    Although there can be multiple procedures on the same visit_date for the same pet_id, I see no reason to split those further: a date could (in theory) be stored in 2 bytes, and splitting that data would create more overhead (plus an extra index).

    You would also want to change pet_age to pet_birth_date since the age changes over time.

    Since this is the first exercise in your list, the above will probably be more than enough.

    Going even further:

    An owner can have multiple pets, so another table could be created:

    Pet_owners: owner_id, owner_name
    

    and then only use owner_id in the Pets table. In a real system there would be customer_id, name, address, phone, email, etc. - so that should always be in a separate table.

    You could even do the same for pet_type and store the id in 1 or 2 bytes, but it all depends on the type of queries you want to do later on the data.

提交回复
热议问题