I'm relatively new into designing databases so this is my first project and I'm trying to understand better it's structure.
I need to create a SQLite database where there will be a simple USERS table with personal information such as name, sex, age, etc.
Then, each user will Add as many Dog names they want on a List.
I was considering to use more than 1 table, where every user will have it's own ID and it will be assigned with the other table, however I'm not sure how to do it without leaving the user with a limit of dogs.
How should I design it to support as many dogs as the user wants?
-
3You do it by using a DOG table that references the USERS table. Read up about foreign keys - this is exactly the concept that allows you to represent unlimited relations between things.Kilian Foth– Kilian Foth2015年11月03日 11:39:45 +00:00Commented Nov 3, 2015 at 11:39
-
Thank you Kilian. I'll do some research on this topic. But it looks that I'm on the right path, isn't it?Machado– Machado2015年11月03日 11:53:06 +00:00Commented Nov 3, 2015 at 11:53
-
1In addition to the above, what you are trying to create is called a "one to many" relationship.GisMofx– GisMofx2015年11月03日 12:35:31 +00:00Commented Nov 3, 2015 at 12:35
-
This is one of the more common relationships, so try to understand the relationship well. If you're not sure the relationship between two entites, ask yourself, "Does one X have many Y?" followed by "Does one Y have many X?" If the answer is Yes/No or No/Yes, you have one-to-many. If it is No/No, then it is one to one, and if you have Yes/Yes, you have many-to-many.Neil– Neil2015年11月03日 13:07:06 +00:00Commented Nov 3, 2015 at 13:07
-
Interesting. That's a one-to-many relationship.Machado– Machado2015年11月03日 13:11:03 +00:00Commented Nov 3, 2015 at 13:11
1 Answer 1
You can have a separate table for dogs where you have the general information for each dog and then an owner field.
If you you don't like that, you can also have a separate table for dogs and then a relationship table that relates the dogs to their respective owners.