MOP-002 Tak Berkata Tapi Menunjukkanwiąz
<|endoftext|>Design a database schema for a school library that can efficiently manage books, students, borrowings, and fines. Include appropriate tables, fields, and relationships.
To design a school library database schema that can efficiently manage books, students, borrowings, and fines, we need to consider the following entities and their relationships:
1. **Books Table**: Stores information about each book in the library.
2. **Students Table**: Stores information about each student who can borrow books.
3. **Borrowings Table**: Tracks each borrowing of a book by a student.
4. **Fines Table**: Tracks any fines incurred by students for overdue books.
Let's break down the schema design step by step:
### Database Schema
1. **Books Table**
- **BookID** (Primary Key, integer)
- **Title** (string)
- **Author** (string)
- **ISBN** (string, unique)
- **PublicationYear** (integer)
- **Genre** (string)
- **Status** (enum: Available, Borrowed, Lost)
2. **Students Table**
- **StudentID** (Primary Key, integer)
- **FirstName** (string)
- **LastName** (string)
- **DateOfBirth** (date)
- **EnrollmentYear** (integer)
- **Address** (string)
- **PhoneNumber** (string)
3. **Borrowings Table**
- **BorrowingID** (Primary Key, integer)
- **BookID** (Foreign Key referencing Books.BookID, integer)
- **StudentID** (Foreign Key referencing Students.StudentID, integer)
- **BorrowDate** (date)
- **DueDate** (date)
- **ReturnDate** (date, nullable)
4. **Fines Table**
- **FineID** (Primary Key, integer)
- **StudentID** (Foreign Key referencing Students.StudentID, integer)
- **FineAmount** (decimal)
- **DateIncurred** (date)
- **PaymentStatus** (enum: Unpaid, PartiallyPaid, Paid)
### Relationships
1. **One-to-Many**: A book can be borrowed by multiple students, but each borrowing is linked to a specific book.
- **Association**: `Books.BookID` is a foreign key in `Borrowings`.
2. **One-to-Many**: A student can borrow multiple books, but each borrowing is linked to a specific student.
- **Association**: `Students.StudentID` is a foreign key in `Borrowings`.
3. **One-to-Many**: A student can incur multiple fines, but each fine is linked to a specific student.
- **Association**: `Students.StudentID` is a foreign key in `Fines`.
### Example SQL Statements for Creating Tables
```sql
CREATE TABLE Books (
BookID INT PRIMARY KEY,
Title VARCHAR(255),
Author VARCHAR(100),
ISBN VARCHAR(13) UNIQUE,
PublicationYear INT,
Genre VARCHAR(100),
Status ENUM('Available', 'Borrowed', 'Lost') DEFAULT 'Available'
);
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DateOfBirth DATE,
EnrollmentYear INT,
Address VARCHAR(255),
PhoneNumber VARCHAR(20)
);
CREATE TABLE Borrowings (
BorrowingID INT PRIMARY KEY,
BookID INT,
StudentID INT,
BorrowDate DATE NOT NULL,
DueDate DATE NOT NULL,
ReturnDate DATE,
FOREIGN KEY (BookID) REFERENCES Books(BookID),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);
CREATE TABLE Fines (
FineID INT PRIMARY KEY,
StudentID INT,
FineAmount DECIMAL(10, 2) NOT NULL,
DateIncurred DATE NOT NULL,
PaymentStatus ENUM('Unpaid', 'PartiallyPaid', 'Paid'),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);
```
This schema ensures that the library system can effectively manage books, student information, borrowing transactions, and any associated fines.
11 Sep 2013