Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I'm trying to develop an app where different users can log in and save the data.
for example user1 wants to add his/her favorite food items they consume daily.
Now I want to save this data in the database.
but the problem is I already have a database for the food items.
user detail database is also there, user_id will be primary key.
but how to design a good schema for this requirement is my question. I want it to design in such a way that meal (collection of food) can be saved at once. If only someone could guide me on the schema designing, I will be able to procedd further.

Thanks a lot for taking time to read my query :)
Posted
Comments
Abinash_Sahoo 6-Apr-14 12:13pm    
Do you have a predefined list of menu? Like menu1 contains foodItem1, foodItem3, foodItem4; and menu2 contains foodItem2, foodItem3, foodItem5 ... like that? Or any user can choose any food item from the list?
ineffable.an 6-Apr-14 12:37pm    
any user can chose from the food list already provided, but the user saved meanls will be specific to the user. so I will map the food items with the user.
Abinash_Sahoo 6-Apr-14 14:09pm    
well, in that case you can create a table which will store UserId and FoodItemId, one row for each food item per user
ineffable.an 6-Apr-14 14:50pm    
can you give me an example?

1 solution

If you have UserDetail and FoodItem tables like this:

UserDetail Table:
------------------
UserId UserName
------ --------
1 John
2 Steve

FoodItem Table:
------------------
ItemId ItemName
------ --------
1 Burger
2 Burrito
3 Coke

Now you can create UserFoodItem table like
UserId ItemId
------ --------
1 1
1 3
2 2
2 3

Here UserId and ItemId both will be primary key in UserFoodItem table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900