{"id":31687819,"url":"https://github.com/sahil-pillania/postgresql_library-system-management","last_synced_at":"2026-02-13T21:37:16.504Z","repository":{"id":313063764,"uuid":"1048558215","full_name":"Sahil-pillania/postgresql_library-system-management","owner":"Sahil-pillania","description":"Dataset Queries project developed using postgresql. Solved multiple problems.","archived":false,"fork":false,"pushed_at":"2025-09-03T16:56:02.000Z","size":519,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-12T06:36:55.221Z","etag":null,"topics":["postgresql","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/Sahil-pillania.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-01T16:26:36.000Z","updated_at":"2025-09-09T17:22:29.000Z","dependencies_parsed_at":"2025-09-03T18:39:06.706Z","dependency_job_id":"938db1cb-986e-4278-bfd2-25ea810c1f72","html_url":"https://github.com/Sahil-pillania/postgresql_library-system-management","commit_stats":null,"previous_names":["sahil-pillania/postgresql_library-system-management"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Sahil-pillania/postgresql_library-system-management","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahil-pillania%2Fpostgresql_library-system-management","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahil-pillania%2Fpostgresql_library-system-management/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahil-pillania%2Fpostgresql_library-system-management/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahil-pillania%2Fpostgresql_library-system-management/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sahil-pillania","download_url":"https://codeload.github.com/Sahil-pillania/postgresql_library-system-management/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahil-pillania%2Fpostgresql_library-system-management/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29418667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-13T06:24:03.484Z","status":"ssl_error","status_checked_at":"2026-02-13T06:23:12.830Z","response_time":78,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["postgresql","sql"],"created_at":"2025-10-08T10:30:39.471Z","updated_at":"2026-02-13T21:37:16.496Z","avatar_url":"https://github.com/Sahil-pillania.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Library Management System using SQL Project --P2\n\n## Project Overview\n\n**Project Title**: Library Management System  \n**Level**: Intermediate \n**Database**: \"library_project\"\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![Project-image](library.jpg)\n\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. **Advanced SQL Queries**: Develop complex queries to analyze and retrieve specific data.\n\n## Project Structure\n\n### 1. Database Setup\n\n![Project-image](library_erd.png)\n\n- **Database Creation**: Created a database named `library_db`.\n- **Table Creation**: Created tables for branches, employees, members, books, issued status, and return status. Each table includes relevant columns and relationships.\n\n```sql\nCREATE DATABASE library_project;\n\nDROP TABLE IF EXISTS branch;\nCREATE TABLE branch\n(\n            branch_id VARCHAR(10) PRIMARY KEY,\n            manager_id VARCHAR(10),\n            branch_address VARCHAR(30),\n            contact_no VARCHAR(15)\n);\n\n\n-- Create table \"Employee\"\nDROP TABLE IF EXISTS employees;\nCREATE TABLE employees\n(\n            emp_id VARCHAR(10) PRIMARY KEY,\n            emp_name VARCHAR(30),\n            position VARCHAR(30),\n            salary DECIMAL(10,2),\n            branch_id VARCHAR(10),\n            FOREIGN KEY (branch_id) REFERENCES  branch(branch_id)\n);\n\n\n-- Create table \"Members\"\nDROP TABLE IF EXISTS members;\nCREATE TABLE members\n(\n            member_id VARCHAR(10) PRIMARY KEY,\n            member_name VARCHAR(30),\n            member_address VARCHAR(30),\n            reg_date DATE\n);\n\n\n\n-- Create table \"Books\"\nDROP TABLE IF EXISTS books;\nCREATE TABLE books\n(\n            isbn VARCHAR(50) PRIMARY KEY,\n            book_title VARCHAR(80),\n            category VARCHAR(30),\n            rental_price DECIMAL(10,2),\n            status VARCHAR(10),\n            author VARCHAR(30),\n            publisher VARCHAR(30)\n);\n\n\n\n-- Create table \"IssueStatus\"\nDROP TABLE IF EXISTS issued_status;\nCREATE TABLE issued_status\n(\n            issued_id VARCHAR(10) PRIMARY KEY,\n            issued_member_id VARCHAR(30),\n            issued_book_name VARCHAR(80),\n            issued_date DATE,\n            issued_book_isbn VARCHAR(50),\n            issued_emp_id VARCHAR(10),\n            FOREIGN KEY (issued_member_id) REFERENCES members(member_id),\n            FOREIGN KEY (issued_emp_id) REFERENCES employees(emp_id),\n            FOREIGN KEY (issued_book_isbn) REFERENCES books(isbn) \n);\n\n\n\n-- Create table \"ReturnStatus\"\nDROP TABLE IF EXISTS return_status;\nCREATE TABLE return_status\n(\n            return_id VARCHAR(10) PRIMARY KEY,\n            issued_id VARCHAR(30),\n            return_book_name VARCHAR(80),\n            return_date DATE,\n            return_book_isbn VARCHAR(50),\n            FOREIGN KEY (return_book_isbn) REFERENCES books(isbn)\n);\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**\n-- Objective: Delete 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**\n-- Objective: Select all books issued by the employee with emp_id = 'E101'.\n```sql\nSELECT * FROM issued_status\nWHERE issued_emp_id = 'E101'\n```\n\n\n**Task 5: List Members Who Have Issued More Than One Book**\n-- Objective: Use 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**: Used 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\nTask 7. **Retrieve All Books in a Specific Category**:\n\n```sql\nSELECT * FROM books\nWHERE category = 'Classic';\n```\n\n8. **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\n9. **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\n10. **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\nTask 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\nTask 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\n\nThank you for your interest in this project!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahil-pillania%2Fpostgresql_library-system-management","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsahil-pillania%2Fpostgresql_library-system-management","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahil-pillania%2Fpostgresql_library-system-management/lists"}