-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
117 lines (106 loc) · 3.17 KB
/
schema.sql
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES latin1 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP SCHEMA IF EXISTS book_bay;
CREATE SCHEMA book_bay;
USE book_bay;
SET AUTOCOMMIT=0;
drop table if exists user;
drop table if exists login_credential;
drop table if exists book;
drop table if exists request;
drop table if exists my_books;
drop table if exists book_review;
drop table if exists history;
drop table if exists user_phone_number;
CREATE TABLE user
(
User_ID VARCHAR(20) NOT NULL,
Name TEXT NOT NULL,
Email_Address VARCHAR(40) NOT NULL,
House_Number VARCHAR(10) ,
Street TEXT NOT NULL,
Locality TEXT NOT NULL,
Postal_Code NUMERIC(6) NOT NULL,
Landmark TEXT ,
City TEXT NOT NULL,
State TEXT NOT NULL,
PRIMARY KEY (User_ID)
);
CREATE TABLE login_credential
(
Password VARCHAR(30) NOT NULL,
User_ID VARCHAR(20) NOT NULL,
PRIMARY KEY (User_ID),
FOREIGN KEY (User_ID) REFERENCES user(User_ID)
);
CREATE TABLE book
(
ISBN VARCHAR(13) NOT NULL,
Book_Name TEXT NOT NULL,
Year INT(4),
Author TEXT,
Language CHAR(30),
PRIMARY KEY (ISBN)
);
CREATE TABLE request
(
Date_of_Request DATETIME NOT NULL,
Request_Message TEXT,
Request_ID INT NOT NULL AUTO_INCREMENT,
borrow_time_duration INT NOT NULL,
completion_flag INT NOT NULL,
User_ID VARCHAR(20) NOT NULL,
ISBN VARCHAR(30) NOT NULL,
Requested_User_ID VARCHAR(20),
PRIMARY KEY (Request_ID),
FOREIGN KEY (User_ID) REFERENCES user(User_ID),
FOREIGN KEY (ISBN) REFERENCES book(ISBN),
FOREIGN KEY (Requested_User_ID) REFERENCES user(User_ID)
);
CREATE TABLE my_books
(
Repayment_Policy TEXT NOT NULL,
Availability INT NOT NULL,
Other_Specifications TEXT,
Security_Money_of_Book INT NOT NULL,
User_ID VARCHAR(20) NOT NULL,
ISBN VARCHAR(13) NOT NULL,
CHECK (Availability in (0,1)),
PRIMARY KEY (User_ID, ISBN),
FOREIGN KEY (User_ID) REFERENCES User(User_ID),
FOREIGN KEY (ISBN) REFERENCES book(ISBN)
);
CREATE TABLE book_review
(
Rating INT NOT NULL,
Review TEXT,
User_ID VARCHAR(20) NOT NULL,
ISBN VARCHAR(13) NOT NULL,
PRIMARY KEY (User_ID, ISBN),
FOREIGN KEY (User_ID) REFERENCES user(User_ID),
FOREIGN KEY (ISBN) REFERENCES book(ISBN)
);
CREATE TABLE history
(
User_ID VARCHAR(20) NOT NULL,
ISBN VARCHAR(13) NOT NULL,
PRIMARY KEY (User_ID, ISBN),
FOREIGN KEY (User_ID) REFERENCES user(User_ID),
FOREIGN KEY (ISBN) REFERENCES book(ISBN)
);
CREATE TABLE user_phone_number
(
Phone_Number NUMERIC(10) NOT NULL,
User_ID VARCHAR(20) NOT NULL,
Is_Primary INT NOT NULL,
PRIMARY KEY (Phone_Number, User_ID),
FOREIGN KEY (User_ID) REFERENCES user(User_ID)
);