-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprac 4
277 lines (238 loc) · 10.7 KB
/
prac 4
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
student@student-OptiPlex-3070:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.33-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2021, 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 Library;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| A45 |
| Company_info |
| Employee |
| Employee1 |
| Library |
| STUDENT |
| School |
| Student |
| abb |
| abc |
| abcv |
| exibition |
| gaurav |
| laxmi |
| mysql |
| performance_schema |
| samarth |
| shreyash1 |
| sk |
| sss |
| student |
| sys |
| users |
+--------------------+
24 rows in set (0.22 sec)
mysql> use Library;
Database changed
mysql> create table Borrower(Roll_no int, Name varchar(30), Date_of_issue date, Name_of_book varchar(30) , Status varchar(30));
Query OK, 0 rows affected (0.27 sec)
mysql> create table Fine(Roll_no int, Date date, Amt int);
Query OK, 0 rows affected (0.24 sec)
mysql> show tables;
+-------------------+
| Tables_in_Library |
+-------------------+
| Borrower |
| Fine |
+-------------------+
2 rows in set (0.00 sec)
mysql> describe Borrower;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Roll_no | int(11) | YES | | NULL | |
| Name | varchar(30) | YES | | NULL | |
| Date_of_issue | date | YES | | NULL | |
| Name_of_book | varchar(30) | YES | | NULL | |
| Status | varchar(30) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
mysql> describe Fine;
+---------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| Roll_no | int(11) | YES | | NULL | |
| Date | date | YES | | NULL | |
| Amt | int(11) | YES | | NULL | |
+---------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> insert into Borrower( Roll_no, Name, Date_of_issue, Name_of_book, Status) values (1, 'ABC', '2022-10-09', 'book1', 'issued'), (2, 'ABB', '2022-10-08', 'book2', 'Not_issued'), (3, 'ACC', '2022-09-22', 'book3', 'issued');
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from Borrower;
+---------+------+---------------+--------------+------------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+------------+
| 1 | ABC | 2022-10-09 | book1 | issued |
| 2 | ABB | 2022-10-08 | book2 | Not_issued |
| 3 | ACC | 2022-09-22 | book3 | issued |
+---------+------+---------------+--------------+------------+
3 rows in set (0.00 sec)
mysql> describe Borrower;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Roll_no | int(11) | YES | | NULL | |
| Name | varchar(30) | YES | | NULL | |
| Date_of_issue | date | YES | | NULL | |
| Name_of_book | varchar(30) | YES | | NULL | |
| Status | varchar(30) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> delimiter $
mysql> create procedure Pl1( In rln01 int(3), Name1 varchar(30))
-> begin declare i_date date;
-> declare diff int;
-> select Date_of_issue into i_date from Borrower where Roll_no = rln01 and Name_of_book= Name1;
-> select DATEDIFF ( CURDATE(), i_date) into diff;
-> if diff >15 then update Borrower set Status='R' where Roll_no=rln01 and Name_of_Book= Name1;
-> End if;
-> End;
-> $ delimiter;
Query OK, 0 rows affected (0.05 sec)
->
[1]+ Stopped mysql -u root -p
student@student-OptiPlex-3070:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.33-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2021, 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> use Library;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from Borrower;
+---------+------+---------------+--------------+------------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+------------+
| 1 | ABC | 2022-10-09 | book1 | issued |
| 2 | ABB | 2022-10-08 | book2 | Not_issued |
| 3 | ACC | 2022-09-22 | book3 | issued |
+---------+------+---------------+--------------+------------+
3 rows in set (0.00 sec)
mysql> update Borrower set Status=I where Roll_no=1;
ERROR 1054 (42S22): Unknown column 'I' in 'field list'
mysql> update Borrower set Status='I' where Roll_no=1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Borrower;
+---------+------+---------------+--------------+------------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+------------+
| 1 | ABC | 2022-10-09 | book1 | I |
| 2 | ABB | 2022-10-08 | book2 | Not_issued |
| 3 | ACC | 2022-09-22 | book3 | issued |
+---------+------+---------------+--------------+------------+
3 rows in set (0.00 sec)
mysql> update Borrower set Status='I' where Roll_no=2;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Borrower set Status='I' where Roll_no=3;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-10-09 | book1 | I |
| 2 | ABB | 2022-10-08 | book2 | I |
| 3 | ACC | 2022-09-22 | book3 | I |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql> call Pl1(2, 'book2');
Query OK, 1 row affected (0.00 sec)
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-10-09 | book1 | I |
| 2 | ABB | 2022-10-08 | book2 | I |
| 3 | ACC | 2022-09-22 | book3 | I |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql> call Pl1(3, 'book3');
Query OK, 1 row affected (0.00 sec)
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-10-09 | book1 | I |
| 2 | ABB | 2022-10-08 | book2 | I |
| 3 | ACC | 2022-09-22 | book3 | I |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql> update Borrower set Date='2022-07-22' where Roll_no=1;
ERROR 1054 (42S22): Unknown column 'Date' in 'field list'
mysql> update Borrower set Date_of_issue='2022-07-22' where Roll_no=1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-07-22 | book1 | I |
| 2 | ABB | 2022-10-08 | book2 | I |
| 3 | ACC | 2022-09-22 | book3 | I |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql> call Pl1(1,'book1');
Query OK, 1 row affected (0.04 sec)
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-07-22 | book1 | R |
| 2 | ABB | 2022-10-08 | book2 | I |
| 3 | ACC | 2022-09-22 | book3 | I |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql> update Borrower set Date_of_issue='2022-07-20' where Roll_no=2;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Borrower set Date_of_issue='2022-06-20' where Roll_no=3;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-07-22 | book1 | R |
| 2 | ABB | 2022-07-20 | book2 | I |
| 3 | ACC | 2022-06-20 | book3 | I |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql> call Pl1(3,'book3');
Query OK, 1 row affected (0.04 sec)
mysql> select * from Borrower;
+---------+------+---------------+--------------+--------+
| Roll_no | Name | Date_of_issue | Name_of_book | Status |
+---------+------+---------------+--------------+--------+
| 1 | ABC | 2022-07-22 | book1 | R |
| 2 | ABB | 2022-07-20 | book2 | I |
| 3 | ACC | 2022-06-20 | book3 | R |
+---------+------+---------------+--------------+--------+
3 rows in set (0.00 sec)
mysql>