简体   繁体   中英

Pet Database Design

Let me rephrase my question since I don't think I accurately described it.

I'm trying to determine the best way to link pet entries to their appropriate breed table based on the value in their species field. Pets can have more than one breed if they are a mix. Would a setup like this be efficient? Or is there a better way to do this. Should I separate species into a separate table as well?

Would this complicate joining results since I have to determine the value of species before knowing what breed table to join with?

Table Pets:

id | name  | species
1  | Spot  | Dog
2  | Kitty | Cat
3  | Chip  | Dog
4  | Sunny | Horse

Table Dog Breeds:

id | breed
1  | German Shepherd
2  | Golden Retreiver
3  | Black Lab
4  | Boxer

Table Cat Breeds:

id | breed
1  | Tabby
2  | Persian
3  | British Shorthair
4  | Ragdoll

Table pet_dog_breed

pet_id | dog_breed_id
1      | 2
1      | 4

Table pet_cat_breed

pet_id | cat_breed_id
2      | 1

Thanks!

Table Pets:

id | name 1 | Spot 2 | Kitty 3 | Chip 4 | Sunny

Table Breeds:

id | breed | species 1 | German Shepherd | Dog 2 | Golden Retreiver | Cat 3 | Black Lab | Dog 4 | Boxer | Cat

Table pet_breed

pet_id | breed_id 1 | 2 1 | 4

I would like to layout the database in this shape

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM