patternsqlMinor
Dog Adoption Database Design
Viewed 0 times
databaseadoptiondesigndog
Problem
Apologies if this isn't the norm, but I am seeking advice for the database design for 'dog rescue/adoption'.
I've done my normalization research and this is my first attempt at database design. Any tips/feedbacks/criticism?
The trickiest part was dealing with dogs/users/organisations and representing who owns a dog.
-
a dog can belong to an organisation.
An organisation can have many organisation users.
Think animal shelter/pound
-
a dog can belong to an organisation user. think a one man band with a large property housing multiple dogs at a time
-
a dog can belong to a single user, not attached to any organisation. think someone moving overseas and they need to find their dog a new owner
So, the dog table has to have either an organisation ID or a user ID attached to it, or both. Perhaps a trigger stating that one must be not null.
I've done my normalization research and this is my first attempt at database design. Any tips/feedbacks/criticism?
The trickiest part was dealing with dogs/users/organisations and representing who owns a dog.
-
a dog can belong to an organisation.
An organisation can have many organisation users.
Think animal shelter/pound
-
a dog can belong to an organisation user. think a one man band with a large property housing multiple dogs at a time
-
a dog can belong to a single user, not attached to any organisation. think someone moving overseas and they need to find their dog a new owner
So, the dog table has to have either an organisation ID or a user ID attached to it, or both. Perhaps a trigger stating that one must be not null.
Solution
You can have organisation, user, and location all have a reference to a common table representing something that can be an owner to a dog. Then dog can have a single reference to this table. Here is a diagram explaining.
dog.owner_id references can_own_dog.can_own_dog_id, in case that isn't clear. Each of the can_own_dog foreign keys is unique in their table, ideally unique across all three tables.
I'm not sure if you're familiar with object-oriented programming, but the idea is similar to multiple classes implementing a single interface.
On another note, your diagram says "Users can have multiple locations", and "Dogs can have multiple locations". I think these mean to say "Locations can have many users" and "Locations can have many dogs"?
dog.owner_id references can_own_dog.can_own_dog_id, in case that isn't clear. Each of the can_own_dog foreign keys is unique in their table, ideally unique across all three tables.
I'm not sure if you're familiar with object-oriented programming, but the idea is similar to multiple classes implementing a single interface.
On another note, your diagram says "Users can have multiple locations", and "Dogs can have multiple locations". I think these mean to say "Locations can have many users" and "Locations can have many dogs"?
Context
StackExchange Database Administrators Q#123019, answer score: 2
Revisions (0)
No revisions yet.