-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary_db.sql
More file actions
38 lines (34 loc) · 1.03 KB
/
library_db.sql
File metadata and controls
38 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Create the database if it doesn't already exist
CREATE DATABASE IF NOT EXISTS library_db;
-- Switch to using the new database
USE library_db;
-- Create the table for Books
CREATE TABLE books (
book_id VARCHAR(20) PRIMARY KEY,
title VARCHAR(100) NOT NULL,
author VARCHAR(50),
total_copies INT NOT NULL,
available_copies INT NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
download_link VARCHAR(200),
download_limit INT
);
-- Create the table for Users
CREATE TABLE users (
user_id VARCHAR(20) PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) UNIQUE,
phone VARCHAR(15),
is_active BOOLEAN DEFAULT TRUE
);
-- Create the table for tracking borrowed books
CREATE TABLE borrow_records (
record_id INT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(20) NOT NULL,
book_id VARCHAR(20) NOT NULL,
borrow_date DATE NOT NULL,
return_date DATE,
is_returned BOOLEAN DEFAULT FALSE,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (book_id) REFERENCES books(book_id)
);