{"id":20604376,"url":"https://github.com/bhushan148/library-management-system","last_synced_at":"2026-05-29T08:31:20.306Z","repository":{"id":255208418,"uuid":"848369509","full_name":"Bhushan148/Library-Management-System","owner":"Bhushan148","description":"The 📚 Library Management System using SQL Project involves designing and managing a library database. It includes  setting up tables for branches, employees, and books, performing 🛠️ CRUD operations, and using 📋 CTAS for advanced querying. The project aims to demonstrate expertise in 💾 SQL database design, 📝 data manipulation, and 📊 analysis.","archived":false,"fork":false,"pushed_at":"2024-08-30T14:32:46.000Z","size":233,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T16:50:06.941Z","etag":null,"topics":["mysql","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bhushan148.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-27T16:28:25.000Z","updated_at":"2024-09-02T06:58:35.000Z","dependencies_parsed_at":"2024-08-28T16:32:18.588Z","dependency_job_id":"7b87a91d-75c8-41c9-90ca-8341a9bf850a","html_url":"https://github.com/Bhushan148/Library-Management-System","commit_stats":null,"previous_names":["bhushan148/library-management-system"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Bhushan148/Library-Management-System","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhushan148%2FLibrary-Management-System","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhushan148%2FLibrary-Management-System/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhushan148%2FLibrary-Management-System/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhushan148%2FLibrary-Management-System/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bhushan148","download_url":"https://codeload.github.com/Bhushan148/Library-Management-System/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhushan148%2FLibrary-Management-System/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33644153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql","sql"],"created_at":"2024-11-16T09:22:39.458Z","updated_at":"2026-05-29T08:31:20.290Z","avatar_url":"https://github.com/Bhushan148.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📚 Library Management System using SQL Project\n\n## 📝 Project Overview 📝\n\n**🔖Project Title**: Library Management System 🏛️\n\n**💾 Database**: `Library_Management_System`\n\nThis project demonstrates the implementation of a Library Management System using SQL. It includes creating and managing tables, performing CRUD operations, and executing advanced SQL queries. The goal is to showcase skills in database design, manipulation, and querying.\n\n![Library_project](https://github.com/najirh/Library-System-Management---P2/blob/main/library.jpg)\n\n## 🎯 Objectives\n\n1. **Set up the Library Management System Database**: Create and populate the database with tables for branches, employees, members, books, issued status, and return status.\n2. **CRUD Operations**: Perform Create, Read, Update, and Delete operations on the data.\n3. **CTAS (Create Table As Select)**: Utilize CTAS to create new tables based on query results.\n4. **Data Analysis \u0026 Findings**: Develop complex queries to analyze and retrieve specific data.\n\n# \u003cspan style=\"color:green; font-weight:bold;\"\u003e🏗️ Project Structure\u003c/span\u003e\n\n## 1. 🔧 Database Setup\n![ERD](https://github.com/Bhushan148/Library-Management-System/blob/main/Screenshot%202024-08-28%20115609.png)\n\n- **Database Creation:** Created a database named `Library_Management_System`.\n- **Table Creation:** Created tables for branches, employees, members, books, issued status, and return status. Each table includes relevant columns and relationships.\n\n## 📚 Library Management System Database Setup\n\n### Objective 🎯\n- **Ensure Data Integrity:** Correct data types and constraints maintain accurate data and relationships.\n- **Optimize Performance:** Efficient data types and indexes improve query speed and system performance.\n- **Align Schema:** Adjustments ensure the schema meets application requirements and business rules.\n- **Handle Migration Issues:** Resolve inconsistencies from importing data from different systems or devices.\n\n### Importing Tables ⬆️\nWhen importing tables from external sources or devices, data types and constraints may not fully align with MySQL standards. Adjusting the schema ensures compatibility and efficiency.\n\n### Steps 🔢\n\n#### 1. Create and Select Database\n```sql\ncreate database library_management_system;\nuse library_management_system;\n```\n\n#### 2. Update Branch Table\n```sql\nalter table branch\nmodify branch_id varchar(10),\nmodify manager_id varchar(10),\nmodify branch_address varchar(30),\nmodify contact_no varchar(15);\n\nalter table branch\nadd constraint primary key (branch_id);\n\n```\n\n#### 3. Update Employees Table\n```sql\nalter table employees\nmodify emp_id varchar(10),\nmodify emp_name varchar(30),\nmodify position varchar(30),\nmodify salary decimal(10,2),\nmodify branch_id varchar(10);\n\nalter table employees\nadd constraint foreign key (branch_id) references branch(branch_id);\n\n```\n\n#### 4. Update Members Table\n```sql\nalter table members\nmodify member_id varchar(10),\nmodify member_name varchar(30),\nmodify member_address varchar(30),\nmodify reg_date date;\n\nalter table members\nadd constraint primary key (member_id);\n```\n\n#### 5. Update Books Table\n```sql\nalter table books\nmodify isbn varchar(50),\nmodify book_title varchar(80),\nmodify category varchar(30),\nmodify rental_price decimal(10,2),\nmodify status varchar(10),\nmodify author varchar(30),\nmodify publisher varchar(30);\n\nalter table books\nadd constraint primary key (isbn);\n\n```\n\n#### 6. Update Issued Status Table\n```sql\nalter table issued_status\nmodify issued_id varchar(10),\nmodify issued_member_id varchar(30),\nmodify issued_book_name varchar(80),\nmodify issued_date date,\nmodify issued_book_isbn varchar(50),\nmodify issued_emp_id varchar(10);\n\nalter table issued_status\nadd constraint primary key (issued_id);\n\nalter table issued_status\nadd constraint fk_issued_member foreign key (issued_member_id) references members(member_id),\nadd constraint fk_issued_emp foreign key (issued_emp_id) references employees(emp_id),\nadd constraint fk_issued_book foreign key (issued_book_isbn) references books(isbn);\n```\n\n#### 7. Update Return Status Table\n```sql\nalter table return_status\nmodify return_id varchar(10),\nmodify issued_id varchar(30),\nmodify return_book_name varchar(80),\nmodify return_date date,\nmodify return_book_isbn varchar(50);\n\nset foreign_key_checks = 0;\n\nalter table return_status\nadd constraint fk_return_book foreign key (return_book_isbn) references books(isbn),\nadd constraint fk_return_issued foreign key (issued_id) references issued_status(issued_id);\n\nset foreign_key_checks = 1;\n\n```\n\n### 2. CRUD Operations 🛠️\n\n- **Create**: Inserted sample records into the `books` table.\n- **Read**: Retrieved and displayed data from various tables.\n- **Update**: Updated records in the `employees` table.\n- **Delete**: Removed records from the `members` table as needed.\n\n**Task 1: Create a New Book Record**  \n\"978-1-60129-456-2', 'To Kill a Mockingbird', 'Classic', 6.00, 'yes', 'Harper Lee', 'J.B. Lippincott \u0026 Co.')\"\n\n```sql\nINSERT INTO books(isbn, book_title, category, rental_price, status, author, publisher)\nVALUES('978-1-60129-456-2', 'To Kill a Mockingbird', 'Classic', 6.00, 'yes', 'Harper Lee', 'J.B. Lippincott \u0026 Co.');\nSELECT * FROM books;\n```\n**Task 2: Update an Existing Member's Address**\n\n```sql\nUPDATE members\nSET member_address = '125 Oak St'\nWHERE member_id = 'C103';\n```\n\n**Task 3: Delete a Record from the Issued Status Table**  \nDelete the record with issued_id = 'IS121' from the issued_status table.\n\n```sql\nDELETE FROM issued_status\nWHERE   issued_id =   'IS121';\n```\n\n**Task 4: Retrieve All Books Issued by a Specific Employee**  \nSelect all books issued by the employee with emp_id = 'E101'.\n```sql\nSELECT * FROM issued_status\nWHERE issued_emp_id = 'E101'\n```\n\n**Task 5: List Members Who Have Issued More Than One Book**  \nUse GROUP BY to find members who have issued more than one book.\n\n```sql\nSELECT\n    issued_emp_id,\n    COUNT(*)\nFROM issued_status\nGROUP BY 1\nHAVING COUNT(*) \u003e 1\n```\n\n### 3. CTAS (Create Table As Select) 📋\n\n**Task 6: Create Summary Tables:**  \nUsed CTAS to generate new tables based on query results - each book and total book_issued_cnt.\n\n```sql\nCREATE TABLE book_issued_cnt AS\nSELECT b.isbn, b.book_title, COUNT(ist.issued_id) AS issue_count\nFROM issued_status as ist\nJOIN books as b\nON ist.issued_book_isbn = b.isbn\nGROUP BY b.isbn, b.book_title;\n```\n\n\n### 4. Data Analysis \u0026 Findings 📊\n\nThe following SQL queries were used to address specific questions:\n\n**Task 7. Retrieve All Books in a Specific Category**:\n\n```sql\nSELECT * FROM books\nWHERE category = 'Classic';\n```\n\n**Task 8: Find Total Rental Income by Category**:\n\n```sql\nSELECT \n    b.category,\n    SUM(b.rental_price),\n    COUNT(*)\nFROM \nissued_status as ist\nJOIN\nbooks as b\nON b.isbn = ist.issued_book_isbn\nGROUP BY 1\n```\n\n**Task 9: List Members Who Registered in the Last 180 Days**:\n```sql\nSELECT * FROM members\nWHERE reg_date \u003e= CURRENT_DATE - INTERVAL '180 days';\n```\n\n**Task 10: List Employees with Their Branch Manager's Name and their branch details**:\n\n```sql\nSELECT \n    e1.emp_id,\n    e1.emp_name,\n    e1.position,\n    e1.salary,\n    b.*,\n    e2.emp_name as manager\nFROM employees as e1\nJOIN \nbranch as b\nON e1.branch_id = b.branch_id    \nJOIN\nemployees as e2\nON e2.emp_id = b.manager_id\n```\n\n**Task 11. Create a Table of Books with Rental Price Above a Certain Threshold**:\n```sql\nCREATE TABLE expensive_books AS\nSELECT * FROM books\nWHERE rental_price \u003e 7.00;\n```\n\n**Task 12: Retrieve the List of Books Not Yet Returned**\n```sql\nSELECT * FROM issued_status as ist\nLEFT JOIN\nreturn_status as rs\nON rs.issued_id = ist.issued_id\nWHERE rs.return_id IS NULL;\n```\n\n**Task 13: Identify Members with Overdue Books**  \nWrite a query to identify members who have overdue books (assume a 30-day return period). Display the member's_id, member's name, book title, issue date, and days overdue.\n\n```sql\nSELECT \n    ist.issued_member_id,\n    m.member_name,\n    bk.book_title,\n    ist.issued_date,\n    -- rs.return_date,\n    CURRENT_DATE - ist.issued_date as over_dues_days\nFROM issued_status as ist\nJOIN \nmembers as m\n    ON m.member_id = ist.issued_member_id\nJOIN \nbooks as bk\nON bk.isbn = ist.issued_book_isbn\nLEFT JOIN \nreturn_status as rs\nON rs.issued_id = ist.issued_id\nWHERE \n    rs.return_date IS NULL\n    AND\n    (CURRENT_DATE - ist.issued_date) \u003e 30\nORDER BY 1\n```\n\n**Task 14: Update Book Status on Return**  \nWrite a query to update the status of books in the books table to \"Yes\" when they are returned (based on entries in the return_status table).\n\n```sql\nDELIMITER $$\n\nCREATE PROCEDURE update_book_status_on_return()\nBEGIN\n    -- Update book status to 'Yes' for all returned books\n    UPDATE books b\n    JOIN issued_status ist ON b.isbn = ist.issued_book_isbn\n    JOIN return_status rs ON ist.issued_id = rs.issued_id\n    SET b.status = 'Yes'\n    WHERE rs.return_date IS NOT NULL;\n    \n    -- Optional: Notify about the update\n    SELECT 'Book statuses have been updated successfully.' AS message;\nEND $$\n\nDELIMITER ;\n\n-- 1. Insert Five Issued Records\nINSERT INTO issued_status (issued_id, issued_member_id, issued_book_isbn, issued_date) VALUES\n('IS201', 'C120', '978-3-16-148410-0', '2024-08-15'),\n('IS202', 'C121', '978-0-307-58837-1', '2024-08-14'),\n('IS203', 'C122', '978-1-86197-876-9', '2024-08-13'),\n('IS204', 'C123', '978-0-7432-7356-5', '2024-08-12'),\n('IS205', 'C124', '978-0-553-21311-7', '2024-08-11');\n\n-- 2. Insert Three Return Records\nINSERT INTO return_status (return_id, issued_id, return_date, book_quality) VALUES\n('RS201', 'IS201', CURRENT_DATE, 'Good'),\n('RS202', 'IS202', CURRENT_DATE, 'Fair'),\n('RS203', 'IS203', CURRENT_DATE, 'Excellent');\n\n-- 3. Verify Current Book Status\nSELECT b.isbn, b.book_title, b.status\nFROM books b\nJOIN issued_status ist ON b.isbn = ist.issued_book_isbn\nJOIN return_status rs ON ist.issued_id = rs.issued_id\nWHERE rs.return_date IS NOT NULL;\n\n-- 4. Call the Stored Procedure\nCALL update_book_status_on_return();\n\n-- 5. Verify Updated Book Status\nSELECT b.isbn, b.book_title, b.status\nFROM books b\nJOIN issued_status ist ON b.isbn = ist.issued_book_isbn\nJOIN return_status rs ON ist.issued_id = rs.issued_id\nWHERE rs.return_date IS NOT NULL;\n```\n\n**Task 15: Branch Performance Report**  \nCreate a query that generates a performance report for each branch, showing the number of books issued, the number of books returned, and the total revenue generated from book rentals.\n\n```sql\nCREATE TABLE branch_reports AS\nSELECT \n    b.branch_id,\n    b.manager_id,\n    COUNT(DISTINCT ist.issued_id) AS number_of_books_issued,\n    COUNT(DISTINCT rs.return_id) AS number_of_books_returned,\n    SUM(bk.rental_price) AS total_revenue\nFROM issued_status ist\nJOIN employees e ON e.emp_id = ist.issued_emp_id\nJOIN branch b ON e.branch_id = b.branch_id\nLEFT JOIN return_status rs ON rs.issued_id = ist.issued_id\nJOIN books bk ON ist.issued_book_isbn = bk.isbn\nGROUP BY b.branch_id, b.manager_id;\n\n-- Retrieve data from branch_reports table to display the results\nSELECT * FROM branch_reports;\n```\n\n**Task 16: CTAS: Create a Table of Active Members**  \nUse the CREATE TABLE AS (CTAS) statement to create a new table active_members containing members who have issued at least one book in the last 6 months.\n\n```sql\n-- Drop the table if it exists\nDROP TABLE IF EXISTS active_members;\n\n-- Create the 'active_members' table with members who have issued at least one book in the last 2 months\nCREATE TABLE active_members AS\nSELECT *\nFROM members\nWHERE member_id IN (\n    SELECT DISTINCT issued_member_id\n    FROM issued_status\n    WHERE issued_date \u003e= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)\n);\n\n-- Retrieve data from the 'active_members' table to verify the results\nSELECT * FROM active_members;\n```\n\n\n**Task 17: Find Employees with the Most Book Issues Processed**  \nWrite a query to find the top 3 employees who have processed the most book issues. Display the employee name, number of books processed, and their branch.\n\n```sql\nSELECT \n    e.emp_name,\n    COUNT(ist.issued_id) AS no_book_issued\nFROM issued_status AS ist\nJOIN employees AS e\n    ON e.emp_id = ist.issued_emp_id\nJOIN branch AS b\n    ON e.branch_id = b.branch_id\nGROUP BY e.emp_name\nORDER BY no_book_issued DESC\nLIMIT 3;\n```\n\n**Task 18: Identify Members Issuing High-Risk Books**  \nWrite a query to identify members who have issued books more than twice with the status \"damaged\" in the books table. Display the member name, book title, and the number of times they've issued damaged books.    \n```sql\nSELECT\n    m.member_name,\n    bk.book_title,\n    COUNT(ist.issued_id) AS times_issued\nFROM issued_status AS ist\nJOIN members AS m\n    ON m.member_id = ist.issued_member_id\nJOIN books AS bk\n    ON bk.isbn = ist.issued_book_isbn\nWHERE bk.status = 'damaged'\nGROUP BY m.member_name, bk.book_title\nHAVING COUNT(ist.issued_id) \u003e 2\nORDER BY m.member_name, times_issued DESC;\n```\n\n\n**Task 19: Stored Procedure**\nObjective:\nCreate a stored procedure to manage the status of books in a library system.\nDescription:\nWrite a stored procedure that updates the status of a book in the library based on its issuance. The procedure should function as follows:\nThe stored procedure should take the book_id as an input parameter.\nThe procedure should first check if the book is available (status = 'yes').\nIf the book is available, it should be issued, and the status in the books table should be updated to 'no'.\nIf the book is not available (status = 'no'), the procedure should return an error message indicating that the book is currently not available.\n\n```sql\n\n-- Drop the existing procedure if it exists\nDROP PROCEDURE IF EXISTS issue_book;\n\nDELIMITER $$\n\nCREATE PROCEDURE issue_book(\n    IN p_issued_id VARCHAR(10),\n    IN p_issued_member_id VARCHAR(30),\n    IN p_issued_book_isbn VARCHAR(30),\n    IN p_issued_emp_id VARCHAR(10)\n)\nBEGIN\n    DECLARE v_status VARCHAR(10);\n    DECLARE v_message VARCHAR(255);\n\n    -- Check book availability\n    SELECT status INTO v_status\n    FROM books\n    WHERE isbn = p_issued_book_isbn;\n\n    IF v_status = 'yes' THEN\n        -- Issue the book and update its status\n        INSERT INTO issued_status (issued_id, issued_member_id, issued_date, issued_book_isbn, issued_emp_id)\n        VALUES (p_issued_id, p_issued_member_id, CURRENT_DATE, p_issued_book_isbn, p_issued_emp_id);\n\n        UPDATE books\n        SET status = 'no'\n        WHERE isbn = p_issued_book_isbn;\n\n        -- Set success message\n        SET v_message = CONCAT('Success: Book issued. ISBN: ', p_issued_book_isbn);\n    ELSE\n        -- Set error message\n        SET v_message = CONCAT('Error: Book unavailable. ISBN: ', p_issued_book_isbn);\n    END IF;\n\n    -- Output the message\n    SELECT v_message AS message;\nEND $$\n\nDELIMITER ;\n\n-- Test Cases\nCALL issue_book('IS158', 'C108', '978-0-09-957807-9', 'E104'); -- Should return success message\nCALL issue_book('IS156', 'C108', '978-0-375-41398-8', 'E104'); -- Should return error message\n\n-- View Results\nSELECT * FROM books WHERE isbn = '978-0-553-29698-2';\nSELECT * FROM books WHERE isbn = '978-0-375-41398-8';\nSELECT * FROM issued_status;\nSELECT * FROM books;\n\n```\n\n\n\n**Task 20: Create Table As Select (CTAS)**\nObjective: Create a CTAS (Create Table As Select) query to identify overdue books and calculate fines.\n\nDescription: Write a CTAS query to create a new table that lists each member and the books they have issued but not returned within 30 days. The table should include:\n    The number of overdue books.\n    The total fines, with each day's fine calculated at $0.50.\n    The number of books issued by each member.\n    The resulting table should show:\n    Member ID\n    Number of overdue books\n    Total fines\n\n```sql\n-- Create the new table for overdue books and fines\nCREATE TABLE overdue_books_summary AS\nSELECT\n    ist.issued_member_id AS member_id,\n    COUNT(*) AS number_of_overdue_books,\n    SUM(DATEDIFF(CURDATE(), ist.issued_date) * 0.50) AS total_fines\nFROM issued_status ist\nLEFT JOIN return_status rs\n    ON ist.issued_id = rs.issued_id\nWHERE rs.return_date IS NULL\n  AND DATEDIFF(CURDATE(), ist.issued_date) \u003e 30\nGROUP BY ist.issued_member_id;\n\n-- Retrieve data from the new table to verify the results\nSELECT * FROM overdue_books_summary;\n```\n\n## 📄 Reports\n\n- **Database Schema**: Detailed table structures and relationships.\n- **Data Analysis**: Insights into book categories, employee salaries, member registration trends, and issued books.\n- **Summary Reports**: Aggregated data on high-demand books and employee performance.\n\n## 🔚 Conclusion\n\nThis project demonstrates the application of SQL skills in creating and managing a library management system. It includes database setup, data manipulation, and advanced querying, providing a solid foundation for data management and analysis.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhushan148%2Flibrary-management-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhushan148%2Flibrary-management-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhushan148%2Flibrary-management-system/lists"}