This is a PostgreSQL database for a library management system. It contains tables for books, staff, students, and book issues.
To use this database, you will need to have PostgreSQL installed on your machine.
- Create a new database called "library" in PostgreSQL.
- Execute the SQL code in the file library.sql in your PostgreSQL client of choice. This will create the necessary tables, triggers, and functions.
- Start querying the database!
- Books
- ISBN (primary key)
- Title
- Author
- Category
- Price
- Copies
- Staff ID (primary key)
- Username
- Staff Job Type
- Student ID (primary key)
- Username
- Student Email
- Department
- Balance (default 0)
- Issue ID (primary key)
- Student ID (foreign key to Students table)
- Book ISBN (foreign key to Books table)
- Due Date
When a new book issue is added, this function updates the due date to 20 days from the issue date, increments the student's balance by the price of the borrowed book, and decrements the number of copies of the borrowed book.
When a book issue is deleted, this function decrements the student's balance by the price of the returned book, and increments the number of copies of the returned book.
- Before inserting a new book issue, this trigger executes the issue_book_func function.
- Before deleting a book issue, this trigger executes the return_book_func function.
The default port for PostgreSQL is 5432.