0% found this document useful (0 votes)
4 views3 pages

SQL Project

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

SQL Project

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

Database Schema

Create Database Book Library

Tables:

1. Books
o book_id (INT, Primary Key)
o title (VARCHAR)
o author (VARCHAR)
o published_year (INT)
o genre (VARCHAR)
2. Members
o member_id (INT, Primary Key)
o name (VARCHAR)
o join_date (DATE)
3. Loans
o loan_id (INT, Primary Key)
o book_id (INT, Foreign Key)
o member_id (INT, Foreign Key)
o loan_date (DATE)
o return_date (DATE)

Data

Books

book_id title author published_year genre


1 1984 George Orwell 1949 Dystopian
2 To Kill a Mockingbird Harper Lee 1960 Fiction
F. Scott
3 The Great Gatsby 1925 Fiction
Fitzgerald
4 The Catcher in the Rye J.D. Salinger 1951 Fiction

Members

member_id name join_date


1 Alice Johnson 2022-01-15
2 Bob Smith 2023-03-22
member_id name join_date
3 Charlie Brown 2023-06-10

Loans

loan_id book_id member_id loan_date return_date


1 1 1 2023-01-10 2023-01-24
2 2 2 2023-04-01 2023-04-15
3 3 1 2023-05-05 NULL

Queries
 Retrieve all books
 Find all books by a specific author (George Orwell)
 Get all members who joined after a specific date (2023-01-01)
 Count the number of books in each genre:
 Select all books published after 1950

 Get the title and author of all books


 Find a member by name (Alice Johnson)
 Select all loans with their loan dates
 Get the names of all members who joined in 2023
 Find the book with a specific title
 Select all books by title in alphabetical order
 Find all members who have a name starting with 'B'
 Select the loan date for all loans made by member with member_id 2

Additional Queries

 Retrieve all loans with member details and book information


 Find members who have borrowed books but have not returned them (return_date is
NULL)
 Count the number of books borrowed by each member
 List all genres of books borrowed by a specific member (e.g., Alice Johnson)
 Identify members who have borrowed books published before 1950
 Find the most borrowed book
 Get the details of loans that overlap a given date (e.g., 2023-05-10)
 Find all books that have never been loaned
 Identify members who borrowed multiple books on the same day
 List the most recent loan for each book
 Retrieve the total number of books borrowed by members in each year
 Find members who have borrowed books from every genre:
 Get the genre with the highest number of loans
 List all books along with their loan count and the most recent loan date

You might also like