My intentions to design the database schema for the small pet vaccination application. Inside Pet table I want to store details about the pets and if specific vaccination is required. There are 3-4 vaccination types(VT1, VT2, Vt3, VT4), which is stored inside Vaccine_Type table. For each vaccination type there are vaccines from various vendors, so I decided to store that information inside Vaccine table. Vaccination details are stored inside associative table - Vaccination. Inside which I have: pet_id, vaccination_type, vaccine_id, veterinarian_id, vaccination_date and expiation_date, if expiration date is over active field is set to False, indicating that vaccination is no more active and requires new vaccination. Kindly advise how can link this information into Pet table, to show which vaccination Type requires revaccination. And advice if the database schema is correct , or could be optimized more.
I would modify a little bit.
When you want to check if a pet has any expired vaccinations, do the following:
As a general concept, store data in the database. Anything that requires to be calculated does not go in a field, it goes in the application, using the data in the database.
Another concept, do not link things that can be derived from other links. This respects the normal forms.
So:
Pet
petid, PK
name, NN
speciesid, FK (Species.speciesid), NN
Species
speciesid, PK
name, NN
Vet
vetid, PK
name, NN
Vaccine
vaccineid, PK
name, NN
vaccinetypeid, FK (Vaccinetype.vaccinetypeid), NN
activeperiod, NN
Vaccinetype
vaccinetypeid, PK
name, NN
Vaccine_Species
vaccineid, FK (Vaccine.vaccineid)
Species, FK (Species.speciesid)
Vaccination
vaccinationid
vetid, FK (Vet.vetid)
petid, FK (Pet.petid)
vaccineid, FK (Vaccine.vaccineid)
date, NN
Legend:
Notes: