0% found this document useful (0 votes)
5 views4 pages

3307 Dbms 4

Uploaded by

akhidudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

3307 Dbms 4

Uploaded by

akhidudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

mysql> create database library;

Query OK, 1 row affected (0.05 sec)

mysql> use library;


Database changed
mysql> create table books(id int primary key,book_name varchar(100),author
varchar(100),publisher varchar(100) );
Query OK, 0 rows affected (0.13 sec)

mysql> desc books;


+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| book_name | varchar(100) | YES | | NULL | |
| author | varchar(100) | YES | | NULL | |
| publisher | varchar(100) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
4 rows in set (0.05 sec)

mysql> insert into books values(001,'DSA mastered','vinay singhal','AKpb'),


-> (002,'lord of the rings','angelina mclare','LA bros'),
-> (003,'1000 bc','kasprocvich','kanfgaroo'),
-> (004,'chanakya neeti','vineet agarwal','the hindu'),
-> (005,'who will die','robin sharma','the hindu').
-> (005,'dont waste time','harshit singh','the bisht');
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 '.
(005,'dont waste time','harshit singh','the bisht')' at line 5
mysql> insert into books values(001,'DSA mastered','vinay singhal','AKpb'),
-> (002,'lord of the rings','angelina mclare','LA bros'),
-> (003,'1000 bc','kasprocvich','kanfgaroo'),
-> (004,'chanakya neeti','vineet agarwal','the hindu'),
-> (005,'who will die','robin sharma','the hindu'),
-> (005,'dont waste time','harshit singh','harshit csk');
ERROR 1062 (23000): Duplicate entry '5' for key 'books.PRIMARY'
mysql> insert into books values(001,'DSA mastered','vinay singhal','AKpb'),
-> (002,'lord of the rings','angelina mclare','LA bros'),
-> (003,'1000 bc','kasprocvich','kanfgaroo'),
-> (004,'chanakya neeti','vineet agarwal','the hindu'),
-> (005,'who will die','robin sharma','the hindu'),
-> (006,'dont waste time','harshit singh','harshit csk');
Query OK, 6 rows affected (0.01 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from books;


+----+-------------------+-----------------+-------------+
| id | book_name | author | publisher |
+----+-------------------+-----------------+-------------+
| 1 | DSA mastered | vinay singhal | AKpb |
| 2 | lord of the rings | angelina mclare | LA bros |
| 3 | 1000 bc | kasprocvich | kanfgaroo |
| 4 | chanakya neeti | vineet agarwal | the hindu |
| 5 | who will die | robin sharma | the hindu |
| 6 | dont waste time | harshit singh | harshit csk |
+----+-------------------+-----------------+-------------+
6 rows in set (0.00 sec)

mysql> create table borrower(roll_no int primary key,name varchar(100),issue_date


date,book_name varchar(100),status varchar(10));
Query OK, 0 rows affected (0.03 sec)

mysql> desc borrower;


+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| roll_no | int | NO | PRI | NULL | |
| name | varchar(100) | YES | | NULL | |
| issue_date | date | YES | | NULL | |
| book_name | varchar(100) | YES | | NULL | |
| status | varchar(10) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> insert into borrower values(3301,'adarsh',2022-9-01,'who will


die','pending');
ERROR 1292 (22007): Incorrect date value: '2012' for column 'issue_date' at row 1
mysql> insert into borrower values(3301,'adarsh','2022-9-01','who will
die','pending');
Query OK, 1 row affected (0.00 sec)

mysql> insert into borrower values(3302,'abhay','2022-8-11','chanakya


neeti','pending');
Query OK, 1 row affected (0.01 sec)

mysql> insert into borrower values(3321,'harshit singh','2022-7-01','dont waste


time','pending');
Query OK, 1 row affected (0.01 sec)

mysql> insert into borrower values(3305,'aditya','2021-06-01','DSA


mastered','pending');
Query OK, 1 row affected (0.01 sec)

mysql> select *from borrower;


+---------+---------------+------------+-----------------+---------+
| roll_no | name | issue_date | book_name | status |
+---------+---------------+------------+-----------------+---------+
| 3301 | adarsh | 2022-09-01 | who will die | pending |
| 3302 | abhay | 2022-08-11 | chanakya neeti | pending |
| 3305 | aditya | 2021-06-01 | DSA mastered | pending |
| 3321 | harshit singh | 2022-07-01 | dont waste time | pending |
+---------+---------------+------------+-----------------+---------+
4 rows in set (0.00 sec)

mysql> create table fine(roll_no int primary key,issue_date date,return_date date,


amount int);
Query OK, 0 rows affected (0.03 sec)

mysql> delimiter ;;
mysql> create procedure return_book(in roll_no int) begin declare amount int;
declare issue_date date; declare return_date date; declare borrowed_days int;
-> declare exit handler for sqlexception select 'some error occured!!'; select
borrower.issue_date into issue_date from borrower where borrower.roll_no=roll_no;
select curdate() into return_date; select datediff(return_date, issue_date) into
borrowed_days; set amount=0; if borrowed_days>15 and borrowed_days<=30 then set
amount=borrowed_days * 5; elseif borrowed_days>30 then set amount=(borrowed_days-
30) *50 +30 * 5; end if; insert into fine
values(roll_no,issue_date,return_date,amount); updateborrower set status='returned'
where borrower.roll_no =roll_no;
-> 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 'set
status='returned' where borrower.roll_no =roll_no;
end' at line 2
mysql> delimiter ;;
mysql> create procedure return_book(in roll_no int) begin declare amount int;
declare issue_date date; declare return_date date; declare borrowed_days int;
-> declare exit handler for sqlexception select 'some error occured!!'; select
borrower.issue_date into issue_date from borrower where borrower.roll_no=roll_no;
select curdate() into return_date; select datediff(return_date, issue_date) into
borrowed_days; set amount=0; if borrowed_days>15 and borrowed_days<=30 then set
amount=borrowed_days * 5; elseif borrowed_days>30 then set amount=(borrowed_days-
30) *50 +30 * 5; end if; insert into fine
values(roll_no,issue_date,return_date,amount); update borrower set
status='returned' where borrower.roll_no =roll_no;
-> end;;
Query OK, 0 rows affected (0.03 sec)

mysql> delimiter ;
mysql> call retunr_book(3301);
ERROR 1305 (42000): PROCEDURE library.retunr_book does not exist
mysql> call return_book(3301);
Query OK, 1 row affected (0.02 sec)

mysql> call return_book(3305);


Query OK, 1 row affected (0.01 sec)

mysql> call return_book(33021);


Query OK, 0 rows affected (0.01 sec)

mysql> select *from borrower;


+---------+---------------+------------+-----------------+----------+
| roll_no | name | issue_date | book_name | status |
+---------+---------------+------------+-----------------+----------+
| 3301 | adarsh | 2022-09-01 | who will die | returned |
| 3302 | abhay | 2022-08-11 | chanakya neeti | pending |
| 3305 | aditya | 2021-06-01 | DSA mastered | returned |
| 3321 | harshit singh | 2022-07-01 | dont waste time | pending |
+---------+---------------+------------+-----------------+----------+
4 rows in set (0.00 sec)

mysql> select
fine.roll_no,borrower.name,fine.issue_date,fine.return_date,fine.amount from fine
inner join borrower on fine.roll_no=borrower.roll_no;
+---------+--------+------------+-------------+--------+
| roll_no | name | issue_date | return_date | amount |
+---------+--------+------------+-------------+--------+
| 3301 | adarsh | 2022-09-01 | 2022-09-16 | 0 |
| 3305 | aditya | 2021-06-01 | 2022-09-16 | 22250 |
+---------+--------+------------+-------------+--------+
2 rows in set (0.00 sec)

mysql> call return_book(3302);


Query OK, 1 row affected (0.01 sec)

mysql> select *from borrower;


+---------+---------------+------------+-----------------+----------+
| roll_no | name | issue_date | book_name | status |
+---------+---------------+------------+-----------------+----------+
| 3301 | adarsh | 2022-09-01 | who will die | returned |
| 3302 | abhay | 2022-08-11 | chanakya neeti | returned |
| 3305 | aditya | 2021-06-01 | DSA mastered | returned |
| 3321 | harshit singh | 2022-07-01 | dont waste time | pending |
+---------+---------------+------------+-----------------+----------+
4 rows in set (0.00 sec)

mysql> call return_book(3321);


Query OK, 1 row affected (0.01 sec)

mysql> select * from borrower;


+---------+---------------+------------+-----------------+----------+
| roll_no | name | issue_date | book_name | status |
+---------+---------------+------------+-----------------+----------+
| 3301 | adarsh | 2022-09-01 | who will die | returned |
| 3302 | abhay | 2022-08-11 | chanakya neeti | returned |
| 3305 | aditya | 2021-06-01 | DSA mastered | returned |
| 3321 | harshit singh | 2022-07-01 | dont waste time | returned |
+---------+---------------+------------+-----------------+----------+
4 rows in set (0.00 sec)

mysql> select
fine.roll_no,borrower.name,fine.issue_date,fine.return_date,fine.amount from fine
inner join borrower on fine.roll_no=borrower.roll_no;
+---------+---------------+------------+-------------+--------+
| roll_no | name | issue_date | return_date | amount |
+---------+---------------+------------+-------------+--------+
| 3301 | adarsh | 2022-09-01 | 2022-09-16 | 0 |
| 3302 | abhay | 2022-08-11 | 2022-09-16 | 450 |
| 3305 | aditya | 2021-06-01 | 2022-09-16 | 22250 |
| 3321 | harshit singh | 2022-07-01 | 2022-09-16 | 2500 |
+---------+---------------+------------+-------------+--------+
4 rows in set (0.00 sec)

You might also like