Sqltest 1
Sqltest 1
You are a database administrator for a small public library. You need to create and manage a database
to keep track of books, members, and borrowing information.
Requirements:
2. Table Creation: Create the following tables with the specified columns, data types, and constraints:
* Books:
* Author (VARCHAR(255))
* Genre (VARCHAR(255))
* PublicationYear (INT)
* Members:
* LastName (VARCHAR(255))
* Address (VARCHAR(255))
* City (VARCHAR(255))
* State (VARCHAR(2))
* ZipCode (VARCHAR(10))
* PhoneNumber (VARCHAR(20))
* Borrowing:
* BorrowDate (DATE)
* ReturnDate (DATE)
* DueDate (DATE)
3. Data Insertion: Insert at least 5 rows of sample data into each of the three tables. Make sure the data
is realistic and consistent. Vary the Genre, Cities and States.
4. Basic Queries:
* Selection with WHERE: Retrieve the Title, Author, and PublicationYear of all books published after
the year 2000.
* Selection with LIKE: Retrieve the FirstName and LastName of all members whose last name starts
with the letter "S".
* Selection with BETWEEN: Retrieve all borrowing records (all columns from the Borrowing table)
where the BorrowDate is between January 1, 2023, and March 31, 2023.
5. Aggregate Functions:
6. Joins:
* Retrieve the Title of the book and the FirstName and LastName of the member who borrowed it for
all borrowing records.
* Retrieve a list of books that are currently not borrowed (i.e., not present in the Borrowing table).
7. GROUP BY:
* Determine the number of books in each Genre. Display the Genre and the number of books in that
genre.
* Find the total FineAmount collected from each member. Display the MemberID and the total fine
amount.
8. Data Manipulation:
* INSERT: Add a new book to the Books table with appropriate values.
* UPDATE: Update the AvailableCopies of a specific book (identified by BookID) after a member
returns the book. Increase the AvailableCopies by 1.
* DELETE: Remove a member from the Members table (identified by MemberID). (Careful: You
might need to deal with foreign key constraints first!)
9. Dropping a Table:
Deliverables:
• SQL CREATE TABLE statements for all three tables (Books, Members, Borrowing).
• SQL INSERT INTO statements with sample data for all three tables.
cribed above (selection with WHERE, LIKE, BETWEEN, aggregate functions, JOINs, GROUP BY).
• SQL statements for inserting, updating, and deleting data.
• SQL statements for dropping the Borrowing table and recreating it.
This scenario provides a comprehensive exercise in SQL database management, covering essential
operations and techniques.