-
-
Notifications
You must be signed in to change notification settings - Fork 240
/
Database Schema.txt
116 lines (88 loc) · 1.99 KB
/
Database Schema.txt
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
CREATE TABLE PERSON
(
"ID" INTEGER not null PRIMARY KEY,
"PNAME" VARCHAR(30) not null,
"PASSWORD" VARCHAR(10) not null,
"ADDRESS" VARCHAR(30) not null,
"PHONE_NO" INTEGER not null
);
CREATE TABLE BOOK
(
"ID" INTEGER not null PRIMARY KEY,
"TITLE" VARCHAR(30) not null,
"AUTHOR" VARCHAR(20) not null,
"SUBJECT" VARCHAR(20) not null,
"IS_ISSUED" BOOLEAN not null
);
CREATE TABLE STAFF
(
"S_ID" INTEGER not null PRIMARY KEY,
"TYPE" VARCHAR(10) not null,
"SALARY" DOUBLE
);
CREATE TABLE CLERK
(
"C_ID" INTEGER not null PRIMARY KEY,
"DESK_NO" INTEGER not null
);
CREATE TABLE LIBRARIAN
(
"L_ID" INTEGER not null PRIMARY KEY,
"OFFICE_NO" INTEGER not null
);
CREATE TABLE BORROWER
(
"B_ID" INTEGER not null PRIMARY KEY
);
CREATE TABLE BORROWED_BOOK
(
"BOOK" INTEGER not null PRIMARY KEY,
"BORROWER" INTEGER not null
);
CREATE TABLE LOAN
(
"L_ID" INTEGER not null PRIMARY KEY,
"BORROWER" INTEGER not null,
"BOOK" INTEGER not null,
"ISSUER" INTEGER not null,
"ISS_DATE" TIMESTAMP not null,
"RECEIVER" INTEGER ,
"RET_DATE" TIMESTAMP ,
"FINE_PAID" BOOLEAN
);
CREATE TABLE ON_HOLD_BOOK
(
"REQ_ID" INTEGER not null PRIMARY KEY,
"BOOK" INTEGER not null,
"BORROWER" INTEGER not null,
"REQ_DATE" DATE not null
);
----------------------------------------FOREIGN KEY CONSTRAINTS----------------------------
ALTER TABLE BORROWED_BOOK
ADD
FOREIGN KEY (BORROWER)REFERENCES BORROWER(B_ID);
ALTER TABLE LOAN
ADD
FOREIGN KEY (BORROWER)REFERENCES BORROWER(B_ID);
ALTER TABLE LOAN
ADD
FOREIGN KEY (ISSUER)REFERENCES STAFF(S_ID);
ALTER TABLE LOAN
ADD
FOREIGN KEY (RECEIVER)REFERENCES STAFF(S_ID);
ALTER TABLE ON_HOLD_BOOK
ADD
FOREIGN KEY (BORROWER)REFERENCES BORROWER(B_ID);
ALTER TABLE LIBRARIAN
ADD
FOREIGN KEY (L_ID)REFERENCES STAFF(S_ID);
ALTER TABLE CLERK
ADD
FOREIGN KEY (C_ID)REFERENCES STAFF(S_ID);
ALTER TABLE STAFF
ADD
FOREIGN KEY (S_ID)REFERENCES PERSON(ID);
ALTER TABLE BORROWER
ADD
FOREIGN KEY (B_ID)REFERENCES PERSON(ID);
-------------------------------------------------------------