and thanks for reading.
I'm making a DB for a puppy shop. I have a table for puppies and a table for owners. A puppy can have one owner, owners can own more than one puppy, but not all puppies are owned. What's a good way to handle this situation?
Thanks for the help.
This question is really aiming at, how do I mark a row as global, and allowed to be viewed by any user?
Solution 1) is the correct one. A puppy can have either no owner or a single owner, so the column is either populated with an existing owner or NULL.
I would have the following tables:
Dog
Owner
DogOwner (contains non-nullable DogID and OwnerID FKs that together make up the PK)
Then, you would do:
select *
from Dog d
left outer join DogOwner do on d.DogID = do.DogID
left outer join Owner o on do.OwnerID = o.OwnerID
This query retrieves all dogs, even those with no owner.
This has a few improvements over your design:
Dog
because dogs don't stay puppies very long (sniff)DogOwner
, because Dogs can have more than one owner. I know mine does!If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With