-- Step 1: Create the Database
CREATE DATABASE IF NOT EXISTS library_db;
USE library_db;
-- Step 2: Create the Books Table
CREATE TABLE IF NOT EXISTS Books (
book_id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
category VARCHAR(255),
isbn VARCHAR(50),
availability BOOLEAN DEFAULT TRUE
);
-- Step 3: Create the Members Table
CREATE TABLE IF NOT EXISTS Members (
member_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
contact VARCHAR(50),
email VARCHAR(255),
membership_date DATE
);
-- Step 4: Create the Transactions Table
CREATE TABLE IF NOT EXISTS Transactions (
transaction_id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT,
member_id INT,
issue_date DATE,
due_date DATE,
return_date DATE,
fine DECIMAL(5,2) DEFAULT 0,
FOREIGN KEY (book_id) REFERENCES Books(book_id),
FOREIGN KEY (member_id) REFERENCES Members(member_id)
);