0% found this document useful (0 votes)
0 views

Library Management SQL Queries

The document outlines SQL queries for managing a library system, including database creation, table definitions for books and book issuers, and various operations such as inserting, updating, deleting, and selecting data. It provides examples of how to handle book information and track issuers along with their borrowing details. Additionally, it includes queries for counting books and grouping them by genre.

Uploaded by

Ojasva Gupta
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)
0 views

Library Management SQL Queries

The document outlines SQL queries for managing a library system, including database creation, table definitions for books and book issuers, and various operations such as inserting, updating, deleting, and selecting data. It provides examples of how to handle book information and track issuers along with their borrowing details. Additionally, it includes queries for counting books and grouping them by genre.

Uploaded by

Ojasva Gupta
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/ 2

SQL Queries for Library Management System

1. CREATE DATABASE library_management_system;

2. USE library_management_system;

3. CREATE TABLE books (book_id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(255),

author VARCHAR(255), genre VARCHAR(255), available_copies INT);

4. CREATE TABLE book_issuers (issuer_id INT PRIMARY KEY, name VARCHAR(255), contact

VARCHAR(255), book_id INT, issue_date DATE, return_date DATE, FOREIGN KEY (book_id)

REFERENCES books(book_id));

5. INSERT INTO books (title, author, genre, available_copies) VALUES ('Harry Potter', 'J.K.

Rowling', 'Fantasy', 5);

6. INSERT INTO books (title, author, genre, available_copies) VALUES ('The Hobbit', 'J.R.R.

Tolkien', 'Adventure', 3);

7. SELECT * FROM books;

8. SELECT title, author FROM books WHERE genre = 'Fantasy';

9. UPDATE books SET available_copies = available_copies + 1 WHERE book_id = 1;

10. DELETE FROM books WHERE title = 'The Hobbit';

11. INSERT INTO book_issuers (issuer_id, name, contact, book_id, issue_date, return_date)

VALUES (1, 'John Doe', '1234567890', 1, '2024-01-01', '2024-01-15');

12. SELECT * FROM book_issuers;

13. SELECT name, contact FROM book_issuers WHERE book_id = 1;


14. SELECT COUNT(*) FROM books;

15. SELECT genre, COUNT(*) FROM books GROUP BY genre;

16. SELECT * FROM books ORDER BY title ASC;

17. SELECT * FROM books WHERE available_copies > 2;

18. SELECT * FROM books WHERE title LIKE '%Harry%';

19. SELECT books.title, book_issuers.name FROM books JOIN book_issuers ON books.book_id =

book_issuers.book_id;

20. SELECT books.title, book_issuers.name FROM books LEFT JOIN book_issuers ON

books.book_id = book_issuers.book_id;

You might also like