-
Notifications
You must be signed in to change notification settings - Fork 2
/
LMS DB Script.sql
104 lines (84 loc) · 3.8 KB
/
LMS DB Script.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
create database LMS;
use LMS;
create table users (
username varchar(30) primary key,
first_name varchar(30),
middle_name varchar(30),
last_name varchar(30),
region varchar(30),
district varchar(30),
street varchar(30),
ward varchar(30),
email varchar(30),
mobile_no int
);
create table login (
username varchar (30),
password varchar (30),
FOREIGN KEY (username) REFERENCES users(username)
);
create table administrator (
username varchar (30),
admin_ID int primary key,
date_employed date,
FOREIGN KEY (username) REFERENCES users(username)
);
create table librarian (
username varchar (30),
librarian_ID int primary key,
date_employed date,
FOREIGN KEY (username) REFERENCES users(username)
);
create table library_member (
username varchar (30),
member_ID int primary key,
date_registered date,
expiry_date date,
FOREIGN KEY (username) REFERENCES users(username)
);
create table books (
book_id int primary key,
book_title varchar (30),
author varchar(30),
book_availability varchar (20)
);
create table payment (
payment_id int primary key,
amount int,
date_paid date,
payment_purpose varchar (50)
);
create table admin_librarian (
admin_id int,
librarian_id int,
PRIMARY KEY (admin_id, librarian_id),
FOREIGN KEY (admin_id) REFERENCES administrator(admin_id),
FOREIGN KEY (librarian_id) REFERENCES librarian(librarian_id)
);
create table librarian_member (
member_id int,
librarian_id int,
PRIMARY KEY (member_id, librarian_id),
FOREIGN KEY (member_id) REFERENCES library_member(member_id),
FOREIGN KEY (librarian_id) REFERENCES librarian(librarian_id)
);
create table librarian_book (
book_id int,
librarian_id int,
PRIMARY KEY (book_id, librarian_id),
FOREIGN KEY (book_id) REFERENCES books(book_id),
FOREIGN KEY (librarian_id) REFERENCES librarian(librarian_id)
);
create table member_payment (
payment_id int,
member_id int,
PRIMARY KEY (payment_id, member_id),
FOREIGN KEY (payment_id) REFERENCES payment(payment_id),
FOREIGN KEY (member_id) REFERENCES library_member(member_id)
);
create table member_book (
member_id int ,
book_id int ,
PRIMARY KEY (member_id, book_id),
FOREIGN KEY (member_id) REFERENCES library_member(member_id)
);