0% found this document useful (0 votes)
8 views2 pages

7349 Assignment4

Uploaded by

subham1495s
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)
8 views2 pages

7349 Assignment4

Uploaded by

subham1495s
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/ 2

-- Create Database

create database library;


use library;

-- Create Table Borrower


create table Borrower(Rollno int(4), Name varchar(20), DateofIssue date, NameofBook
varchar(30), Status varchar(10));

-- Insert Data into Borrower Table


insert into Borrower values(14, 'Ram', '2022-09-19', 'Operating System', 'I');
insert into Borrower values(27, 'Soham', '2022-07-24', 'Object Oriented
Programming', 'I');
insert into Borrower values(34, 'Mohan', '2022-06-12', 'Microprocessor', 'I');
insert into Borrower values(48, 'Om', '2022-04-19', 'Mechanics', 'I');

-- Select All from Borrower


select * from Borrower;

-- Output:
-- | Rollno | Name | DateofIssue | NameofBook | Status |
-- |--------|-------|--------------|----------------------------|--------|
-- | 14 | Ram | 2022-09-19 | Operating System | I |
-- | 27 | Soham | 2022-07-24 | Object Oriented Programming | I |
-- | 34 | Mohan | 2022-06-12 | Microprocessor | I |
-- | 48 | Om | 2022-04-19 | Mechanics | I |

-- Create Table Fine


create table Fine(Rollno int(4), Date date, Amount int(10));

-- Create Procedure to Calculate Fine


delimiter //
create procedure calc_Fine(in r int(10), in b varchar(30))
begin
declare doi date;
declare diff int(3);
select DateofIssue into doi from Borrower where Rollno = r and NameofBook = b;
select datediff(curdate(), doi) into diff;
if diff >= 15 and diff <= 30 then
insert into Fine values(r, curdate(), diff * 5);
end if;
if diff > 30 then
insert into Fine values(r, curdate(), diff * 50);
end if;
end //
delimiter ;

-- Call Procedure to Calculate Fine for Ram (Operating System)


call calc_Fine(14, 'Operating System');

-- Output for Fine:


-- | Rollno | Date | Amount |
-- |--------|------------|--------|
-- | 14 | 2024-10-25 | 38400 |

-- Call Procedure to Calculate Fine for Soham (OOP)


call calc_Fine(27, 'Object Oriented Programming');

-- Call Procedure to Calculate Fine for Mohan (Microprocessor)


call calc_Fine(34, 'Microprocessor');

-- Call Procedure to Calculate Fine for Om (Mechanics)


call calc_Fine(48, 'Mechanics');

-- Select All from Fine


select * from Fine;

-- Output:
-- | Rollno | Date | Amount |
-- |--------|------------|--------|
-- | 14 | 2024-10-25 | 38400 |
-- | 27 | 2024-10-25 | 41250 |
-- | 34 | 2024-10-25 | 43350 |
-- | 48 | 2024-10-25 | 46050 |

-- Create Procedure to Submit Book


delimiter //
create procedure submit(in r int(2))
begin
update Borrower set Status = 'R' where Rollno = r;
delete from Fine where Rollno = r;
end //
delimiter ;

-- Call Procedure to Submit Books


call submit(14);
call submit(27);
call submit(48);
call submit(34);

-- Select All from Fine (After submission)


select * from Fine;

-- Output:
-- | Rollno | Date | Amount |
-- |--------|------|--------|
-- | | | | -- Empty, as all fines are cleared

-- Select All from Borrower (After submission)


select * from Borrower;

-- Output:
-- | Rollno | Name | DateofIssue | NameofBook | Status |
-- |--------|-------|--------------|----------------------------|--------|
-- | 14 | Ram | 2022-09-19 | Operating System | R |
-- | 27 | Soham | 2022-07-24 | Object Oriented Programming | R |
-- | 34 | Mohan | 2022-06-12 | Microprocessor | R |
-- | 48 | Om | 2022-04-19 | Mechanics | R |

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy