question archive You are using the relational data model to design a database that will be used by an online book purchase and recommendation service
Subject:Computer SciencePrice:4.87 Bought7
You are using the relational data model to design a database that will be used by an online book purchase and recommendation service. Think of it like Amazon Books, where customers buy books, review and rate them. When a customer gives a high rating to a book, that means that they like that book. When a customer gives a low rating to a book, that means that they did not like that book.
Your task is to design a database that stores the customers' book purchases, reviews and ratings. This way, you can use this data to analyze what each customer likes to read, and recommend him/her other books accordingly.
Please not that the database design for this application is very simple and straight forward. Keep things simple. Do not try to overdo things.
Please read ALL the questions below before starting to answer them.
Question1:
Using the information above, list three requirements for that online book purchase and recommendation service.
- Hints:
-- The customer should be able to ....
-- The customer should be able to ....
-- The system should store .... about books
-- The system should store .... about customers
Question 2:
List the entities in your data.
Question 3:
List the attributes for each of the entities that you specified in Question 2.
Question 4:
List the relationships between your entities. List any relationship-specific attributes.
Question 5:
Convert your set of entities, attributes and relations into a database schema. Specifically, write down the table names, the columns in each table, and specify which columns are primary keys and which ones are foreign keys.
Question 6:
Using your database design, write an SQL query to retrieve the customer ID's (or customer names, either is fine) of all customers that gave the book "Alice in Wonderland" a rating of 5.
Question 7:
Using your database design, write an SQL query to insert a new purchase done by customer John Smith, whose ID is 1234, to the book "The Three Musketeers", whose ID is 5678.
Answer:
Question1
Online book purchase and recommendation service.
Question 2
The entities in the database design are as follows:
Question 3
The attributes for each of the entity are listed below:
Cust_id , Cust_name, Book_ID
Book_id ,Book_name,Price,Author
Cust_id, Book_id, Rating, Review
Question 4:
The relationship between the Customer, Book, and Rate_review entities are as follows:
Question 5:
The following list specifies the table names, the columns in each table, and specifies the primary keys and the foreign keys.
Customer table:
Cust_id |
Cust_name |
Book_ID |
Primary key: Cust_id
Foreign Key: Book_ID of table book
Book table:
Book_id |
Book_name |
Price |
Author |
Primary key: Book_id
Rate_review table:
Cust_id |
Book_id |
Rating |
Review |
Primary key: { Cust_id ,Book_ID }
Foreign Key: Book_ID of table book and Cust_id of table customer.
Question 6:
To select the customer ID from the customer table that gave the book "Alice in Wonderland" a rating of 5.
SELECT Customer.Cust_id "C_Id",Customer.Cust_name "C_Name",
Rate_review.Rating "Rating" FROM Customer, Rate_review
WHERE Rate_review.rating=5 AND book_name like 'Alice in Wonderland' AND C.cust_id= R.cust_id;
Question 7:
To insert a new purchase done by a customer John Smith, whose ID is 1234, to the book "The Three Musketeers", whose ID is 5678.
INSERT INTO Customer (Cust_id, Cust_name, Book_ID)
VALUES (1234,'John Smith',5678);