-
Notifications
You must be signed in to change notification settings - Fork 0
/
q16*
289 lines (235 loc) · 14.9 KB
/
q16*
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
omickeyee@omickeyee-HP-Pavilion-Laptop-15-cc1xx:~$ sudo mysql
[sudo] password for omickeyee:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 8.0.29-0ubuntu0.22.04.2 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database practical_q16;
Query OK, 1 row affected (0.01 sec)
mysql> use practical_q16;
Database changed
mysql> CREATE TABLE `practical_q16`.`publisher` (
-> `name` VARCHAR(100) NOT NULL,
-> `address` VARCHAR(200) NOT NULL,
-> `phone` VARCHAR(10) NOT NULL,
-> PRIMARY KEY (`name`));
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE `practical_q16`.`book` (
-> `book_ISBN` VARCHAR(50) NOT NULL,
-> `Title` VARCHAR(50) NOT NULL,
-> `publisher_name` VARCHAR(100) NOT NULL,
-> PRIMARY KEY (`book_ISBN`),
-> INDEX `fk_publisher_name_from_publisher_idx` (`publisher_name` ASC) VISIBLE,
-> CONSTRAINT `fk_publisher_name_from_publisher`
-> FOREIGN KEY (`publisher_name`)
-> REFERENCES `practical_q16`.`publisher` (`name`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE);
Query OK, 0 rows affected (0.04 sec)
mysql> CREATE TABLE `practical_q16`.`book_author` (
-> `Book_ISBN` VARCHAR(50) NOT NULL,
-> `Author_Name` VARCHAR(100) NOT NULL,
-> CONSTRAINT `fk_Boook_ISBN_from_Book`
-> FOREIGN KEY (`Book_ISBN`)
-> REFERENCES `practical_q16`.`book` (`book_ISBN`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE);
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE `practical_q16`.`library_branch` (
-> `branch_id` VARCHAR(20) NOT NULL,
-> `Branch` VARCHAR(100) NOT NULL,
-> `Address` VARCHAR(200) NOT NULL,
-> PRIMARY KEY (`branch_id`));
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE `practical_q16`.`borrower` (
-> `card_num` VARCHAR(20) NOT NULL,
-> `Name` VARCHAR(100) NOT NULL,
-> `Address` VARCHAR(200) NOT NULL,
-> `Phone` VARCHAR(10) NOT NULL,
-> PRIMARY KEY (`card_num`));
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE `practical_q16`.`book_copies` (
-> `book_ISBN` VARCHAR(50) NOT NULL,
-> `branch_id` VARCHAR(20) NOT NULL,
-> `Num_copies` INT NULL DEFAULT 0,
-> INDEX `fk_branch_id_from_library_branch_idx` (`branch_id` ASC) VISIBLE,
-> CONSTRAINT `fk_branch_id_from_library_branch`
-> FOREIGN KEY (`branch_id`)
-> REFERENCES `practical_q16`.`library_branch` (`branch_id`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE,
-> CONSTRAINT `fk_book_isbn_from_book`
-> FOREIGN KEY (`book_ISBN`)
-> REFERENCES `practical_q16`.`book` (`book_ISBN`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE);
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE `practical_q16`.`book_loans` (
-> `book_ISBN` VARCHAR(50) NOT NULL,
-> `branch_id` VARCHAR(20) NOT NULL,
-> `card_num` VARCHAR(20) NOT NULL,
-> `date_out` DATE NOT NULL,
-> `date_due` DATE GENERATED ALWAYS AS (DATE_ADD(book_loan.date_out, INTERVAL 15 DAY)) VIRTUAL,
-> PRIMARY KEY (`book_ISBN`, `branch_id`, `card_num`),
-> INDEX `fk_branch_id_from_library_branch_into_book_loan_idx` (`branch_id` ASC) VISIBLE,
-> INDEX `fk_card_num_from_borrower_idx` (`card_num` ASC) VISIBLE,
-> CONSTRAINT `fk_book_isbn_from_book_into_book_loan`
-> FOREIGN KEY (`book_ISBN`)
-> REFERENCES `practical_q16`.`book` (`book_ISBN`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE,
-> CONSTRAINT `fk_branch_id_from_library_branch_into_book_loan`
-> FOREIGN KEY (`branch_id`)
-> REFERENCES `practical_q16`.`library_branch` (`branch_id`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE,
-> CONSTRAINT `fk_card_num_from_borrower`
-> FOREIGN KEY (`card_num`)
-> REFERENCES `practical_q16`.`borrower` (`card_num`)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE);
Query OK, 0 rows affected (0.04 sec)
mysql> INSERT INTO `practical_q16`.`publisher` (`name`, `address`, `phone`) VALUES ('publisher-1', 'ABC, Pune', '1234567890');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`publisher` (`name`, `address`, `phone`) VALUES ('publisher-2', 'Hadapsar, Pune', '1234567890');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`publisher` (`name`, `address`, `phone`) VALUES ('publisher-3', 'Mumbai', '1234567899');;
Query OK, 1 row affected (0.01 sec)
ERROR:
No query specified
mysql> INSERT INTO `practical_q16`.`book` (`book_ISBN`, `Title`, `publisher_name`) VALUES ('book-1', 'Title-1', 'publisher-2');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`book` (`book_ISBN`, `Title`, `publisher_name`) VALUES ('book-2', 'Title-2', 'publisher-1');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book` (`book_ISBN`, `Title`, `publisher_name`) VALUES ('book-3', 'Title-3', 'publisher-1');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book` (`book_ISBN`, `Title`, `publisher_name`) VALUES ('book-4', 'Title-4', 'publisher-3');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-2', 'John Smith');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-1', 'author-1');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-3', 'John Smith');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-4', 'author-4');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-2', 'Second book-2 author');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-1', 'Second book-1 author');
Query OK, 1 row affected (0.01 sec)
mysql> NSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) VALUES ('branch-1', 'Branch One', 'ABC, Pune');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) V' at line 1
mysql> INSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) VALUES ('branch-2', 'Branch Two', 'Hadpasar, Pune');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) VALUES ('branch-4', 'Branch Four', 'Mumbai');
Query OK, 1 row affected (0.00 sec)
mysql> NSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) VALUES ('branch-1', 'Branch One', 'ABC, Pune');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) V' at line 1
mysql> INSERT INTO `practical_q16`.`library_branch` (`branch_id`, `Branch`, `Address`) VALUES ('branch-1', 'Branch One', 'ABC, Pune');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`borrower` (`card_num`, `Name`, `Address`, `Phone`) VALUES ('borrower-1', 'Borrower One', 'ABC, Pune', '1234567890');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`borrower` (`card_num`, `Name`, `Address`, `Phone`) VALUES ('borrower-2', 'Borrower Two', 'Hadapaar, Pune', '1234567899');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`borrower` (`card_num`, `Name`, `Address`, `Phone`) VALUES ('borrower-3', 'Borrower Three', 'Mumbai', '1234567898');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-1', 'branch-1', '2');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-2', 'branch-2', '3');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-3', 'branch-2', '0');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-4', 'branch-1', '2');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-2', 'branch-1', '3');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-3', 'branch-1', '1');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-2', 'branch-4', '2');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_copies` (`book_ISBN`, `branch_id`, `Num_copies`) VALUES ('book-4', 'branch-2', '1');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_loans` (`book_ISBN`, `branch_id`, `card_num`, `date_out`) VALUES ('book-1', 'branch-1', 'borrower-1', '2014-06-16');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_loans` (`book_ISBN`, `branch_id`, `card_num`, `date_out`) VALUES ('book-3', 'branch-1', 'borrower-1', '2014-06-16');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_loans` (`book_ISBN`, `branch_id`, `card_num`, `date_out`) VALUES ('book-2', 'branch-2', 'borrower-2', '2015-10-15');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO `practical_q16`.`book_loans` (`book_ISBN`, `branch_id`, `card_num`, `date_out`) VALUES ('book-2', 'branch-4', 'borrower-3', '2015-12-04');
Query OK, 1 row affected (0.01 sec)
mysql> select ELECT book.book_ISBN, book.title, book_author.Author_name FROM book INNER JOIN book_author ON book_author.book_ISBN=book.book_ISBN WHERE book_author.Author_name="John Smith";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.book_ISBN, book.title, book_author.Author_name FROM book INNER JOIN book_author' at line 1
mysql> SELECT book.book_ISBN, book.title, book_author.Author_name FROM book INNER JOIN book_author ON book_author.book_ISBN=book.book_ISBN WHERE book_author.Author_name="John Smith";
+-----------+---------+-------------+
| book_ISBN | title | Author_name |
+-----------+---------+-------------+
| book-2 | Title-2 | John Smith |
| book-3 | Title-3 | John Smith |
+-----------+---------+-------------+
2 rows in set (0.00 sec)
mysql> CREATE OR REPLACE VIEW `COUNT_OF_AUTHORS` AS SELECT COUNT(*) AS `No of Authors`, book_author.book_ISBN FROM book_author GROUP BY book_author.book_ISBN;
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> SELECT * FROM COUNT_OF_AUTHORS;
+---------------+-----------+
| No of Authors | book_ISBN |
+---------------+-----------+
| 2 | book-1 |
| 2 | book-2 |
| 1 | book-3 |
| 1 | book-4 |
+---------------+-----------+
4 rows in set (0.01 sec)
mysql> CREATE OR REPLACE VIEW `MULTIPLE_BOOK_BORROW` AS SELECT COUNT(*) AS `No of Books`, borrower.*, book_loans.book_ISBN, book_loans.date_out FROM book_loans INNER JOIN borrower ON borrower.card_num=book_loans.card_num WHERE book_loans.date_out="2014-06-16" GROUP BY card_num;
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT borrower.*, book_loans.branch_id, book_loans.date_out, COUNT(*) AS `No of Books` FROM borrower INNER JOIN book_loans ON book_loans.card_num=borrower.card_num WHERE borrower.card_num IN (SELECT card_num FROM `MULTIPLE_BOOK_BORROW`) GROUP BY borrower.card_num;
ERROR 1055 (42000): Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'practical_q16.book_loans.book_ISBN' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql> SELECT borrower.*, book_loans.branch_id, book_loans.date_out, COUNT(*) AS `No of Books` FROM borrower INNER JOIN book_loans ON book_loans.card_num=borrower.card_num WHERE borrower.card_num IN (SELECT card_num FROM `MULTIPLE_BOOK_BORROW`) GROUP BY borrower.card_num;
ERROR 1055 (42000): Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'practical_q16.book_loans.book_ISBN' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql> SELECT borrower.*, book_loans.branch_id, book_loans.date_out, COUNT(*) AS `No of Books` FROM borrower INNER JOIN book_loans ON book_loans.card_num=borrower.card_num WHERE borrower.card_num IN (SELECT card_num FROM `ERROR 1055 (42000): Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'practical_q16.book_loans.book_ISBN' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql> delimiter &&
mysql> create trigger CAPITAL LETTERS
-> before insert
-> on book_author for each row
-> begin
-> set new.Author_Name=UPPER(NEW.Author_Name);
-> end &&
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LETTERS
before insert
on book_author for each row
begin
set new.Author_Name=UP' at line 1
mysql> create trigger CAPITAL LETTERS before insert on book_author for each row begin set new.Author_Name=UPPER(NEW.Author_Name); end&&^C
mysql> delimiter &&
mysql> create trigger capital_letter before insert on book_author for each row begin set new.Author_Name=UPPER(NEW.Author_Name); end&&
Query OK, 0 rows affected (0.01 sec)
mysql> delimeter ;
-> //
-> ;
-> ^C
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-4', 'Second book-4 author');
-> ;
-> &&
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO `practical_q16`.`book_author` (`Book_ISBN`, `Author_Name`) VALUES ('book-4', 'Second book-4 author'); ;&&
Query OK, 1 row affected (0.01 sec)
mysql> select * from book_author;
-> &&
+-----------+----------------------+
| Book_ISBN | Author_Name |
+-----------+----------------------+
| book-2 | John Smith |
| book-1 | author-1 |
| book-3 | John Smith |
| book-4 | author-4 |
| book-2 | Second book-2 author |
| book-1 | Second book-1 author |
| book-4 | SECOND BOOK-4 AUTHOR |
| book-4 | SECOND BOOK-4 AUTHOR |
+-----------+----------------------+
8 rows in set (0.00 sec)
mysql>