forked from schemaspy/schemaspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.ddl
297 lines (283 loc) · 12.3 KB
/
library.ddl
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
drop database if exists library;
create database library;
commit;
connect library;
create table ADDRESS (
addressId integer auto_increment,
address1 varchar(50) not null comment 'Address line 1',
address2 varchar(50) comment 'Address line 2 (optional)',
city varchar(30) not null,
state char(2) not null,
zip varchar(10) not null comment "Dash req'd for zip+4",
primary key(AddressId)
) engine=InnoDB COMMENT='Address details';
create table PUBLISHER (
publisherId integer auto_increment,
name varchar(64) not null,
address integer,
phone varchar(16),
primary key(publisherId),
foreign key(address) references ADDRESS(addressId),
index(name)
) engine=InnoDB;
create table BOOK (
isbn bigint,
title varchar(128) not null,
publisherId integer auto_increment not null,
primary key (isbn),
foreign key (publisherId) references PUBLISHER(publisherId),
index (title)
) engine=InnoDB COMMENT='Book details';
create table author (
authorId integer auto_increment,
firstName varchar(32) not null,
middleName varchar(32) null,
lastName varchar(32) not null,
primary key (authorId),
index (lastName)
) engine=InnoDB;
create table book_author (
isbn bigint,
authorId integer comment 'FK intentionally omitted to show an implied relationship',
primary key (isbn, authorId),
foreign key (isbn) references BOOK(isbn)
) engine=InnoDB;
-- foreign key (authorId) references author(authorId)
create table LIBRARY_BRANCH (
branchId integer auto_increment auto_increment,
name varchar(64) not null,
address integer not null,
primary key(BranchId),
foreign key(Address) references ADDRESS(AddressId)
) engine=InnoDB;
create table BOOK_LOCATION (
isbn bigint,
branchId integer not null,
numCopies integer not null,
primary key(isbn, branchId),
foreign key(isbn) references BOOK(isbn),
foreign key(branchId) references LIBRARY_BRANCH(branchId)
) engine=InnoDB;
create table BORROWER (
cardNo integer auto_increment,
firstName varchar(32) not null,
middleName varchar(32) null,
lastName varchar(32) not null,
address integer,
phone varchar(16),
primary key(cardNo),
foreign key(Address) references ADDRESS(AddressId),
index(lastName, firstName)
) engine=InnoDB;
create table borrowed_book (
isbn bigint,
branchId integer not null,
cardNo integer not null,
borrowDate date not null,
dueDate date not null,
primary key (isbn, branchId, cardNo),
foreign key (isbn) references BOOK(isbn),
foreign key (branchId) references LIBRARY_BRANCH(branchId),
foreign key (cardNo) references BORROWER(cardNo),
index (DueDate)
) engine=InnoDB;
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 2, '123');
insert into borrower values(null, 'firstName', '', 'lastName', 1, '123');
insert into publisher values(null, 'AW', 3, '123');
insert into publisher values(null, 'AW', 3, '123');
insert into publisher values(null, 'AW', 3, '123');
insert into publisher values(null, 'AW', 3, '123');
insert into publisher values(null, 'AW', 3, '123');
insert into book values(100, 100, 1);
insert into book values(101, 100, 1);
insert into book values(102, 100, 1);
insert into book values(103, 100, 1);
insert into book values(104, 100, 1);
insert into book values(105, 100, 1);
insert into book values(106, 100, 1);
insert into book values(107, 100, 1);
insert into book values(108, 100, 1);
insert into book values(109, 100, 1);
insert into book values(110, 100, 1);
insert into book values(111, 100, 1);
insert into book values(112, 100, 1);
insert into book values(113, 100, 1);
insert into book values(114, 100, 1);
insert into book values(115, 100, 1);
insert into book values(116, 100, 1);
insert into book values(117, 100, 1);
insert into book values(118, 100, 1);
insert into book values(119, 100, 1);
insert into book values(120, 100, 1);
insert into book values(121, 100, 1);
insert into book values(122, 100, 1);
insert into book values(123, 100, 1);
insert into book values(124, 100, 1);
insert into book values(125, 100, 1);
insert into book values(126, 100, 1);
insert into book values(127, 100, 1);
insert into book values(128, 100, 1);
insert into book values(129, 100, 1);
insert into book values(130, 100, 1);
insert into book values(131, 100, 1);
insert into book values(132, 100, 1);
insert into book values(133, 100, 1);
insert into book values(134, 100, 1);
insert into book values(135, 100, 1);
insert into book values(136, 100, 1);
insert into book values(137, 100, 1);
insert into book values(138, 100, 1);
insert into book values(139, 100, 1);
insert into book values(140, 100, 1);
insert into book values(141, 100, 1);
insert into book values(142, 100, 1);
insert into book values(143, 100, 1);
insert into book values(144, 100, 1);
insert into book values(145, 100, 1);
insert into book values(146, 100, 1);
insert into book values(147, 100, 1);
insert into book values(148, 100, 1);
insert into book values(149, 100, 1);
insert into book values(150, 100, 1);
insert into book values(151, 100, 1);
insert into book values(152, 100, 1);
insert into book values(153, 100, 1);
insert into book values(154, 100, 1);
insert into book values(155, 100, 1);
insert into book values(156, 100, 1);
insert into book values(157, 100, 1);
insert into book values(158, 100, 1);
insert into book values(159, 100, 1);
insert into book values(160, 100, 1);
insert into book values(161, 100, 1);
insert into book values(162, 100, 1);
insert into book values(163, 100, 1);
insert into book values(164, 100, 1);
insert into book values(165, 100, 1);
insert into book values(166, 100, 1);
insert into book values(167, 100, 1);
insert into book values(168, 100, 1);
insert into book values(169, 100, 1);
insert into book values(170, 100, 1);
insert into book values(171, 100, 1);
insert into book values(172, 100, 1);
insert into book values(173, 100, 1);
insert into book values(174, 100, 1);
insert into book values(175, 100, 1);
insert into book values(176, 100, 1);
insert into book values(177, 100, 1);
insert into book values(178, 100, 1);
insert into book values(179, 100, 1);
insert into library_branch values(null, 'Central', 5);
insert into book_location values(100, 1, 1);
insert into book_location values(101, 1, 1);
insert into book_location values(102, 1, 1);
insert into book_location values(103, 1, 1);
insert into book_location values(104, 1, 1);
insert into book_location values(105, 1, 1);
insert into book_location values(106, 1, 1);
insert into book_location values(107, 1, 1);
insert into book_location values(108, 1, 1);
insert into book_location values(109, 1, 1);
insert into book_location values(110, 1, 1);
insert into book_location values(111, 1, 1);
insert into book_location values(112, 1, 1);
insert into book_location values(113, 1, 1);
insert into book_location values(114, 1, 1);
insert into book_location values(115, 1, 1);
insert into book_location values(116, 1, 1);
insert into book_location values(117, 1, 1);
insert into book_location values(118, 1, 1);
insert into book_location values(119, 1, 1);
insert into book_location values(120, 1, 1);
insert into book_location values(121, 1, 1);
insert into book_location values(122, 1, 1);
insert into book_location values(123, 1, 1);
insert into book_location values(124, 1, 1);
insert into book_location values(125, 1, 1);
insert into book_location values(126, 1, 1);
insert into book_location values(127, 1, 1);
insert into book_location values(128, 1, 1);
insert into book_location values(129, 1, 1);
insert into book_location values(130, 1, 1);
insert into book_location values(131, 1, 1);
insert into book_location values(132, 1, 1);
insert into book_location values(133, 1, 1);
insert into book_location values(134, 1, 1);
insert into book_location values(135, 1, 1);
insert into book_location values(136, 1, 1);
insert into book_location values(137, 1, 1);
insert into book_location values(138, 1, 1);
insert into book_location values(139, 1, 1);
insert into book_location values(140, 1, 1);
insert into book_location values(141, 1, 1);
insert into book_location values(142, 1, 1);
insert into book_location values(143, 1, 1);
insert into book_location values(144, 1, 1);
insert into book_location values(145, 1, 1);
insert into book_location values(146, 1, 1);
insert into book_location values(147, 1, 1);
insert into book_location values(148, 1, 1);
insert into book_location values(149, 1, 1);
insert into borrowed_book values(100, 1, 1, '1999-10-31', '1999-10-31');
insert into borrowed_book values(101, 1, 2, '1999-10-31', '1999-10-31');
insert into library_branch values(null, 'Central', 8);
insert into library_branch values(null, 'Central', 7);
insert into library_branch values(null, 'Central', 5);
insert into author values(null, "author1", null, "author1");
insert into author values(null, "author2", null, "author2");
insert into author values(null, "author3", null, "author3");
insert into author values(null, "author4", null, "author4");
insert into author values(null, "author5", null, "author5");
insert into author values(null, "author6", null, "author6");
insert into author values(null, "author7", null, "author7");
insert into author values(null, "author8", null, "author8");
insert into author values(null, "author9", null, "author9");
insert into book_author values(101, 1);
insert into book_author values(101, 2);
insert into book_author values(102, 3);
insert into book_author values(103, 4);
insert into book_author values(104, 5);
insert into book_author values(105, 6);
insert into book_author values(106, 7);
insert into book_author values(107, 8);
-- select branchname, count(*) from library_branch group by branchname, branchid;
-- insert into borrower values(null, 'akshai', 9, '456');
commit;