![]() |
| ||
| determine relationship between two tables? Hello everyone: I am designing a database for a web application. The idea is user should able to pick a restaurant by enter restaurant name, category(American, Chinese) etc I currently have two tables: user table and restaurant table. I have adminID as a primary key in user table. I used adminID as a foreign key in restaurant table. I thought the relationship between these two tables is one to many. For each adminID in user table there are many corresponding records in restaurant table, but each restaurant can have only one adminID in the user table. However, i feel that the restaurant table should only hold information about the restaurant. It is not holding restaurant(s) picked by the user, I feel like there should be 3rd table to hold uid and res_id that connect user table and restaurant table. Please help me to clarify the relationship between these two tables. Should I add 3rd table in this case? I appreciate your help! create table command: create table User( |
| ||
| Re: determine relationship between two tables? Yes, a third table would be appropriate in this situation. I would call the table something like "rating" and have attributes like this: ID(PK), UserID(FK), RestaurantID(FK), Rating, DateRated, etc... |
| ||
| Re: determine relationship between two tables? Quote:
Thanks for the reply. I am confused about what relationship shall I use. please give me some suggestions. ThankdS 1. for a many-to-many relationship, i created a 3rd table: user_restaurants user_restaurants table serve as a link between Users and restaurants. a user can pick several restaurants, one restaurant can be selected by several users. #table Users 2. for a many-to-one relationship. 2a) I created res_id as a foreign key refers back to restaurants. in many to one relation, one user can only select one restaurant but one restaurant can be selected by multiple users. #table Users |
| ||
| Re: determine relationship between two tables? With the rating entity I mentioned, there is a one-to-many relationship from rating to user and a one-to-many rating from rating to restaurant. This will allow each user to rate many restaurants and each restaurant to be rated by many users. There is a many-to-many relationship from users to restaurants with ratings being the cross reference table between the two. |
| All times are GMT -4. The time now is 1:37 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC