Create an app called RestaurantRater that allows the user to save the name and address of a restaurant into a database table

Question

Create an app called RestaurantRater that allows the user to save the name and address of a restaurant into a database table and to save entrée, appetizers, and desserts associated with a specific restaurant in a second related table. The second table should contain the following fields: name (of dish), type
(entrée, dessert, etc.) and a rating on a 1 to 5 scale. The Main Activity should allow the saving of the restaurant and its address and include a button to open a Rate Dish activity. This button should pass the name of the restaurant (or id) to the activity. This value will be used as the foreign key in the second table. (See attributes list after problem 3)

Restaurant
Restaurant Id

Name

Street Address

City

State

Zip Code

 

Dish
Dish id

Name

Type

Rating

Restaurant ID

 

 

Summary

Basically, a SQL query is written which creates two tables as given above and the attributes of the tables are given certain specifications and the two tables are linked through the foreign key.

Explanation

Query to create Restaurant table:

CREATE TABLE Restaurant
(
Restaurantid int primary key,
Name varchar(255),
StreetAddress varchar(255),
City varchar(25),
State varchar(25),
ZipCode int
);

Query to create Dish table:

CREATE TABLE Dish
(
Dishid int primary key,
Name varchar(255),
Type varchar(255),
Rating int,
RestaurantID int foriegn key references Restaurant(Restaurantid),
CHECK(Rating>=1 and Rating<=5)
);

Queries to insert rows in Restaurant table:

insert into Restaurant(Restaurantid, Name, StreetAddress, City,
State, ZipCode) 
values(10, 'Star Bucks', 'Washington, USA','Colombo','Bla bla',12345);

insert into Restaurant(Restaurantid, Name, StreetAddress, City,
State, ZipCode) 
values(11, 'Bawarchi', 'nehru street','Hyderabad','telangana',54321);

Output

Query to insert rows in Dish table:

insert into Dish(Dishid, Name, Type, Rating, RestaurantID) 
values(1,"Chicken","Non-veg",5,10);

insert into Dish(Dishid, Name, Type, Rating, RestaurantID) 
values(2,"Mutton","non-veg",4,11);

Output

 

Also, the read another blog which is to write a relational schema for the diagram.

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *