Author: Alejandro Oviedo
Year: 2025
This repository contains the Final Project for the Database assignature, built entirely in PostgreSQL 18.
It implements a complete library management database with tables, relationships, functions, triggers, views, and real sample data according to the academic requirements.
The file teclab_library_database.sql includes:
- lectores (readers)
- libros (books)
- alquileres (rentals)
- logs_devoluciones (return logs – Activity 4 requirement)
- Primary and foreign keys
- Sequences and auto-increment settings
- View: libros_prestados
- 10 readers
- 10 books
- Rental records
- Automatic logs generated through triggers during book returns
-
devolver_libro(p_lector, p_libro)
Updates the real return date for a book rental. -
libros_prestados()
Returns the total number of books currently rented out. -
log_devolucion()
Trigger function that logs every book return.
trg_log_devolucion
Executes AFTER UPDATE onalquileres, detecting when a real return date is entered and creating a log entry automatically.
- Create a new database named biblioteca
- Right-click → Restore
- Select the file
teclab_library_database.sql - Restore
psql -U postgres -d biblioteca -f teclab_library_database.sql