0% found this document useful (0 votes)
11 views4 pages

Sqltest 1

The document outlines the requirements for managing a library database named LibraryDB, including the creation of three tables: Books, Members, and Borrowing with specified columns and constraints. It details tasks such as data insertion, basic queries, aggregate functions, joins, data manipulation, and dropping/recreating tables. The deliverables include SQL statements for all operations described in the scenario.

Uploaded by

neslybonkwe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Sqltest 1

The document outlines the requirements for managing a library database named LibraryDB, including the creation of three tables: Books, Members, and Borrowing with specified columns and constraints. It details tasks such as data insertion, basic queries, aggregate functions, joins, data manipulation, and dropping/recreating tables. The deliverables include SQL statements for all operations described in the scenario.

Uploaded by

neslybonkwe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Scenario: Managing a Library Database

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:

1. Database Creation: Create a database named LibraryDB.

2. Table Creation: Create the following tables with the specified columns, data types, and constraints:

* Books:

* BookID (INT, PRIMARY KEY, AUTO_INCREMENT)

* Title (VARCHAR(255), NOT NULL)

* Author (VARCHAR(255))

* Genre (VARCHAR(255))

* PublicationYear (INT)

* ISBN (VARCHAR(20), UNIQUE) (International Standard Book Number)

* AvailableCopies (INT, DEFAULT 1)

* Members:

* MemberID (INT, PRIMARY KEY, AUTO_INCREMENT)

* FirstName (VARCHAR(255), NOT NULL)

* LastName (VARCHAR(255))

* Address (VARCHAR(255))

* City (VARCHAR(255))

* State (VARCHAR(2))

* ZipCode (VARCHAR(10))

* PhoneNumber (VARCHAR(20))
* Borrowing:

* BorrowID (INT, PRIMARY KEY, AUTO_INCREMENT)

* BookID (INT, NOT NULL) (FOREIGN KEY referencing Books.BookID)

* MemberID (INT, NOT NULL) (FOREIGN KEY referencing Members.MemberID)

* BorrowDate (DATE)

* ReturnDate (DATE)

* DueDate (DATE)

* FineAmount (DECIMAL(10, 2), DEFAULT 0.00)

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:

* Calculate the total number of books in the Books table.

* Calculate the average FineAmount in the Borrowing table.

* Find the earliest and latest PublicationYear in the Books table.

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:

* Drop the entire Borrowing table. Then recreate it.

Deliverables:

• SQL statements to create the LibraryDB database.

• SQL CREATE TABLE statements for all three tables (Books, Members, Borrowing).

• SQL INSERT INTO statements with sample data for all three tables.

• The SQL queries for each of the tasks des

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.

You might also like