Paper Database Lab
Paper Database Lab
Question:01
You are working for an online bookstore that needs to manage its book and author information
within an existing database. You will perform various operations to retrieve and manipulate the
data.
Part 1: Data Definition and Insertion
1. Create the `Authors` Table with attributes:
AuthorID (INT, PRIMARY KEY)
AuthorName (VARCHAR(255), NOT NULL)
Country (VARCHAR(100))
2. Create the `Books` Table with attributes:
BookID (INT PRIMARY KEY)
Title (VARCHAR(255), NOT NULL)
AuthorID (INT, FOREIGN KEY)
Genre (VARCHAR(100))
Price DECIMAL(10, 2)
3. Insert Data into the `Books` Table:
(1, 'Fundamentals', 101, 'Technology', 50.00)
(2, 'Modern Java', 102, 'Technology', 60.00)
(3, 'Data Science 101', 103, 'Science', 70.00)
(4, 'Introduction to AI', 101, 'Technology', 55.00)
(5, 'Fictional Worlds', 104, 'Fiction', 40.00)
(6, 'Advanced Python', 102, 'Technology', 75.00)
(7, 'Chemistry Basics', 105, 'Science', 45.00)
(8, 'The Art of War', 106, 'History', 30.00)
(9, 'Great Expectations', 104, 'Fiction', 35.00)
4. Insert Data into the `Authors` Table:
(101, 'Alice Thompson', 'USA')
(102, 'Bob Johnson', 'UK')
(103, 'Carol King', 'Canada')
(104, 'David Wright', 'Australia')
(105, 'Eve Martin', 'Germany')
(106, 'Frank Lee', 'China')
Part 2: Queries
5. Retrieve all books, ordered by `Price` in ascending order.
6. Retrieve all books, ordered by `Genre` in ascending order and `Price` in descending
order.
7. Group books by `Genre` and count the number of books in each genre.
8. Retrieve all books where the `Title` contains the word 'Data'.
9. Retrieve the first 5 books with the highest price.
10. Retrieve all books with `AuthorID` IN (101, 102, 103).
11. Retrieve all books with `Price` between 40 and 60.
12. Retrieve all books, grouped by `Genre`, having more than 1 book in the genre.
13. Retrieve all books with `Genre` as 'Technology' and `Price` greater than 50, ordered by
`Price` in descending order.
14. Retrieve the `Title` and `AuthorName` of all books using a join.