0% found this document useful (0 votes)
24 views20 pages

ANSWER

Consider the following five processes, with the length of the CPU burst time given in milliseconds. Process Burst time P1 10 P2 29 P3 3 P4 7 P5 12 Consider the First come First serve (FCFS), Non Preemptive Shortest Job First(SJF), Round Robin(RR) (quantum=10ms) scheduling algorithms.

Uploaded by

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

ANSWER

Consider the following five processes, with the length of the CPU burst time given in milliseconds. Process Burst time P1 10 P2 29 P3 3 P4 7 P5 12 Consider the First come First serve (FCFS), Non Preemptive Shortest Job First(SJF), Round Robin(RR) (quantum=10ms) scheduling algorithms.

Uploaded by

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

ANSWER

1.-- Create Customer table


CREATE TABLE Customer (
Custid INT PRIMARY KEY,
Custname VARCHAR(100),
Age INT,
phone VARCHAR(20)
);

-- Create Loan table


CREATE TABLE Loan (
Loanid INT PRIMARY KEY,
Amount DECIMAL(10,2),
Custid INT,
EMI DECIMAL(10,2),
FOREIGN KEY (Custid) REFERENCES Customer(Custid)
);

-- a) List the name of the customers who have taken a loan for more than Rs.50,000
SELECT Custname
FROM Customer
WHERE Custid IN (SELECT Custid FROM Loan WHERE Amount > 50000);

-- b) List the Customer id of those who have no loan


SELECT Custid
FROM Customer
WHERE Custid NOT IN (SELECT Custid FROM Loan);

-- c) List the total count of loans availed


SELECT COUNT(*) AS TotalLoans
FROM Loan;

-- d) Create a procedure to print the Amount and Custid when the Loanid is given as input.
Handle Exceptions.

DELIMITER //

CREATE PROCEDURE GetLoanInfo(IN loan_id INT)


BEGIN
DECLARE loan_amount DECIMAL(10,2);
DECLARE customer_id INT;

SELECT Amount, Custid INTO loan_amount, customer_id


FROM Loan
WHERE Loanid = loan_id;

IF loan_amount IS NULL THEN


SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Invalid Loan ID';
ELSE
SELECT loan_amount AS Amount, customer_id AS Custid;
END IF;
END//
DELIMITER ;

-- Call the procedure with a Loanid


CALL GetLoanInfo(1); -- Replace 1 with the Loanid you want to check
2. -- Create Employee table

CREATE TABLE Employee (

EmpId INT PRIMARY KEY,

Empname VARCHAR(100),

Sal DECIMAL(10,2),

Deptno INT,

FOREIGN KEY (Deptno) REFERENCES Dept(Deptno)

);

-- Create Dept table

CREATE TABLE Dept (

Deptno INT PRIMARY KEY,

Dname VARCHAR(100),

Loc VARCHAR(100),

DeptmanagerId INT,

FOREIGN KEY (DeptmanagerId) REFERENCES Employee(EmpId)

);

-- a) List the count of Employees and average salary of each department

SELECT

Deptno,

COUNT(EmpId) AS NumEmployees,

AVG(Sal) AS AvgSalary

FROM Employee

GROUP BY Deptno;

-- b) List the employee name, department name, and the salary of all the employees

SELECT
e.Empname,

d.Dname AS DepartmentName,

e.Sal

FROM Employee e

INNER JOIN Dept d ON e.Deptno = d.Deptno;

-- c) Display the Employee name and the respective department manager name

SELECT

e.Empname AS EmployeeName,

d1.Empname AS DepartmentManagerName

FROM Employee e

INNER JOIN Dept d ON e.Deptno = d.Deptno

LEFT JOIN Employee d1 ON d.DeptmanagerId = d1.EmpId;

-- d) Create a function to return the salary of the employee when Empid is given as input
parameter. Handle Exceptions.

DELIMITER //

CREATE FUNCTION GetEmployeeSalary(emp_id INT) RETURNS DECIMAL(10,2)

BEGIN

DECLARE emp_salary DECIMAL(10,2);

SELECT Sal INTO emp_salary

FROM Employee

WHERE EmpId = emp_id;

IF emp_salary IS NULL THEN

SIGNAL SQLSTATE '45000'

SET MESSAGE_TEXT = 'Invalid Employee ID';

ELSE
RETURN emp_salary;

END IF;

END//

DELIMITER ;

-- Call the function with an EmpId

SELECT GetEmployeeSalary(1); -- Replace 1 with the EmpId you want to check

3. -- Create User table

CREATE TABLE User (

Userid INT PRIMARY KEY,

Name VARCHAR(100),

Dept VARCHAR(100),

Bookid INT,

Accdate DATE,

FOREIGN KEY (Bookid) REFERENCES Book(Bookid)

);

-- Create Book table

CREATE TABLE Book (

Bookid INT PRIMARY KEY,

Book_name VARCHAR(100),

Author VARCHAR(100),

Publication VARCHAR(100),

Price DECIMAL(10,2)

);

-- a) List the name of the user who accessed the costliest book

SELECT u.Name

FROM User u
JOIN Book b ON u.Bookid = b.Bookid

WHERE b.Price = (SELECT MAX(Price) FROM Book);

-- b) List the userid and count of books accessed by the user

SELECT Userid, COUNT(Bookid) AS BookCount

FROM User

GROUP BY Userid;

-- c) List the books published by Wiley publisher

SELECT *

FROM Book

WHERE Publication = 'Wiley';

-- d) Write a PL/SQL program to print the details of the book when Bookid is given as input.
Handle appropriate exceptions.

CREATE OR REPLACE PROCEDURE GetBookDetails(p_Bookid IN Book.Bookid%TYPE) AS

v_Book_name Book.Book_name%TYPE;

v_Author Book.Author%TYPE;

v_Publication Book.Publication%TYPE;

v_Price Book.Price%TYPE;

BEGIN

SELECT Book_name, Author, Publication, Price

INTO v_Book_name, v_Author, v_Publication, v_Price

FROM Book

WHERE Bookid = p_Bookid;

DBMS_OUTPUT.PUT_LINE('Book Name: ' || v_Book_name);

DBMS_OUTPUT.PUT_LINE('Author: ' || v_Author);

DBMS_OUTPUT.PUT_LINE('Publication: ' || v_Publication);

DBMS_OUTPUT.PUT_LINE('Price: ' || v_Price);


EXCEPTION

WHEN NO_DATA_FOUND THEN

DBMS_OUTPUT.PUT_LINE('No book found with Bookid ' || p_Bookid);

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('Error occurred: ' || SQLERRM);

END;

-- Call the procedure with a Bookid

BEGIN

GetBookDetails(1); -- Replace 1 with the Bookid you want to check

END;

---------------------------------------------------------------------------------------------------------------------------
4. -- Create Customer table

CREATE TABLE Customer (

Custid INT PRIMARY KEY,

Custname VARCHAR(100),

Addr VARCHAR(255),

phno VARCHAR(20),

panno VARCHAR(20)

);

-- Create Loan table

CREATE TABLE Loan (

Loanid INT PRIMARY KEY,

Amount DECIMAL(10,2),

Interest DECIMAL(5,2),

Custid INT,

FOREIGN KEY (Custid) REFERENCES Customer(Custid)

);
-- Create Account table

CREATE TABLE Account (

Acctno INT PRIMARY KEY,

Accbal DECIMAL(10,2),

Custid INT,

FOREIGN KEY (Custid) REFERENCES Customer(Custid)

);

-- a. Display the Account balance amount of a particular customer "ARUN"

SELECT Accbal

FROM Account

WHERE Custid = (SELECT Custid FROM Customer WHERE Custname = 'ARUN');

-- b. Update the interest with 1% when Accbal of the Custid > 50% of Loan Amount

UPDATE Loan l

SET Interest = Interest + 1

WHERE EXISTS (

SELECT 1

FROM Account a

WHERE a.Custid = l.Custid

AND a.Accbal > (SELECT Amount * 0.5 FROM Loan WHERE Custid = l.Custid)

);

-- c. Create a View with Accbal and Loan Amount of all Customers

CREATE VIEW CustomerBalanceAndLoan AS

SELECT a.Custid, a.Accbal, l.Amount AS LoanAmount

FROM Account a

LEFT JOIN Loan l ON a.Custid = l.Custid;

-- d. Create a trigger which checks for minimum balance in the account.


DELIMITER //

CREATE TRIGGER CheckMinBalance

BEFORE INSERT ON Account

FOR EACH ROW

BEGIN

DECLARE min_balance DECIMAL(10,2) DEFAULT 1000; -- Change this to your minimum


balance requirement

IF NEW.Accbal < min_balance THEN

SIGNAL SQLSTATE '45000'

SET MESSAGE_TEXT = 'Minimum balance requirement not met';

END IF;

END//

DELIMITER ;

5. -- Create Customer table

CREATE TABLE Customer (

Custid INT PRIMARY KEY,

Custname VARCHAR(100),

phno VARCHAR(20),

pan VARCHAR(20),

DOB DATE

);

-- Create HomeLoan table

CREATE TABLE HomeLoan (

HLoanid INT PRIMARY KEY,

Amount DECIMAL(10,2),

Custid INT,

FOREIGN KEY (Custid) REFERENCES Customer(Custid)


);

-- Create VehicleLoan table

CREATE TABLE VehicleLoan (

VLoanid INT PRIMARY KEY,

Amount DECIMAL(10,2),

Custid INT,

FOREIGN KEY (Custid) REFERENCES Customer(Custid)

);

-- a) List the Custid of the customers who have both homeloan and vehicle loan

SELECT Custid

FROM Customer

WHERE Custid IN (SELECT Custid FROM HomeLoan)

AND Custid IN (SELECT Custid FROM VehicleLoan);

-- b) List the Custid of the customers who do not have any loan

SELECT Custid

FROM Customer

WHERE Custid NOT IN (SELECT Custid FROM HomeLoan)

AND Custid NOT IN (SELECT Custid FROM VehicleLoan);

-- c) Create a view with customerid, Customer name, and total loan amount (HomeLoan and
VehicleLoan)

CREATE VIEW CustomerTotalLoan AS

SELECT c.Custid, c.Custname,

COALESCE(SUM(h.Amount), 0) + COALESCE(SUM(v.Amount), 0) AS TotalLoanAmount

FROM Customer c

LEFT JOIN HomeLoan h ON c.Custid = h.Custid

LEFT JOIN VehicleLoan v ON c.Custid = v.Custid

GROUP BY c.Custid, c.Custname;


-- d) Write a trigger which displays the Homeloan details whenever the values are inserted in
the respective table.

DELIMITER //

CREATE TRIGGER DisplayHomeLoanDetails

AFTER INSERT ON HomeLoan

FOR EACH ROW

BEGIN

DECLARE loan_amount DECIMAL(10,2);

DECLARE cust_name VARCHAR(100);

SELECT Amount INTO loan_amount FROM HomeLoan WHERE HLoanid = NEW.HLoanid;

SELECT Custname INTO cust_name FROM Customer WHERE Custid = NEW.Custid;

SELECT CONCAT('New Home Loan details added: Amount = ', loan_amount, ', Customer Name
= ', cust_name) AS Message;

END//

DELIMITER ;

---------------------------------------------------------------------------------------------------------------------------
6. -- Create Marks table

CREATE TABLE Marks (

Regno INT PRIMARY KEY,

Name VARCHAR(100),

Dept VARCHAR(100),

Subj1 INT,

Subj2 INT,

Subj3 INT,

Total INT

);
-- a) Add a column Total in student table and update the Total field with the sum of 3 subject
Marks

ALTER TABLE Marks

ADD Total INT;

UPDATE Marks

SET Total = Subj1 + Subj2 + Subj3;

-- b) Find the second maximum total in the table

SELECT MAX(Total) AS SecondMaxTotal

FROM Marks

WHERE Total < (SELECT MAX(Total) FROM Marks);

-- c) Display the name of the student with maximum total

SELECT Name

FROM Marks

WHERE Total = (SELECT MAX(Total) FROM Marks);

-- d) Write a PL/SQL program to display the report sheet of the students using cursors

-- Assuming you want to display all the data in the Marks table

CREATE OR REPLACE PROCEDURE DisplayReportSheet AS

CURSOR MarksCursor IS

SELECT *

FROM Marks;

v_Regno Marks.Regno%TYPE;

v_Name Marks.Name%TYPE;

v_Dept Marks.Dept%TYPE;

v_Subj1 Marks.Subj1%TYPE;

v_Subj2 Marks.Subj2%TYPE;

v_Subj3 Marks.Subj3%TYPE;
v_Total Marks.Total%TYPE;

BEGIN

OPEN MarksCursor;

LOOP

FETCH MarksCursor INTO v_Regno, v_Name, v_Dept, v_Subj1, v_Subj2, v_Subj3, v_Total;

EXIT WHEN MarksCursor%NOTFOUND;

DBMS_OUTPUT.PUT_LINE('Regno: ' || v_Regno || ', Name: ' || v_Name || ', Dept: ' || v_Dept || ',
Subj1: ' || v_Subj1 || ', Subj2: ' || v_Subj2 || ', Subj3: ' || v_Subj3 || ', Total: ' || v_Total);

END LOOP;

CLOSE MarksCursor;

END;

-- Execute the procedure to display the report sheet

BEGIN

DisplayReportSheet;

END;

7. -- Create stu_details table

CREATE TABLE stu_details (

reg_no INT PRIMARY KEY,

stu_name VARCHAR(100),

DOB DATE,

address VARCHAR(255),

city VARCHAR(100)

);

-- Create mark_details table

CREATE TABLE mark_details (

reg_no INT PRIMARY KEY,

mark1 INT,

mark2 INT,

mark3 INT,
total INT

);

-- a) Alter the table mark_details to add a column average with data type as long

ALTER TABLE mark_details

ADD average FLOAT; -- Assuming "long" is not available in the supported data types, I used
FLOAT instead

-- b) Display the months between the DOB and till date

SELECT TIMESTAMPDIFF(MONTH, DOB, CURDATE()) AS MonthsSinceDOB

FROM stu_details;

-- c) Using alter command drop the column address from the table stu_details

ALTER TABLE stu_details

DROP COLUMN address;

-- d) Write a PL/SQL program to find the sum & average marks of all the students using
procedures

CREATE OR REPLACE PROCEDURE CalculateMarksSummary AS

total_marks INT := 0;

total_students INT := 0;

average_marks FLOAT;

CURSOR MarksCursor IS

SELECT total FROM mark_details;

BEGIN

FOR marks_rec IN MarksCursor LOOP

total_marks := total_marks + marks_rec.total;

total_students := total_students + 1;

END LOOP;

IF total_students <> 0 THEN


average_marks := total_marks / total_students;

DBMS_OUTPUT.PUT_LINE('Total Marks: ' || total_marks);

DBMS_OUTPUT.PUT_LINE('Average Marks: ' || average_marks);

ELSE

DBMS_OUTPUT.PUT_LINE('No student records found.');

END IF;

END;

-- Execute the procedure to find the sum and average marks

BEGIN

CalculateMarksSummary;

END;

8. -- Create Employee table

CREATE TABLE Employee (

Empno INT PRIMARY KEY,

Ename VARCHAR(100),

Job VARCHAR(100),

MgrId INT,

DoB DATE,

DoJ DATE,

Sal DECIMAL(10,2),

Comm DECIMAL(10,2),

Deptno INT,

FOREIGN KEY (Deptno) REFERENCES Department(Deptno)

);

-- Create Department table

CREATE TABLE Department (

Dname VARCHAR(100),
Deptno INT PRIMARY KEY,

Dloc VARCHAR(100)

);

-- a) Display the Emp no, name, salary, and experience of each employee ordered by salary
(highest to lowest)

SELECT Empno, Ename, Sal, DATEDIFF(CURDATE(), DoJ) AS Experience

FROM Employee

ORDER BY Sal DESC;

-- b) List the names of the employee working for “Marketing” Department

SELECT Ename

FROM Employee e

JOIN Department d ON e.Deptno = d.Deptno

WHERE d.Dname = 'Marketing';

-- c) List the names of the employees born in the current month

SELECT Ename

FROM Employee

WHERE MONTH(DoB) = MONTH(CURDATE());

-- d) Write a PL/SQL function to display the details of the employee when Employee no given as
input. Handle Exceptions

CREATE OR REPLACE FUNCTION GetEmployeeDetails(p_Empno INT) RETURNS


VARCHAR(500) AS

DECLARE

v_details VARCHAR(500);

BEGIN

SELECT CONCAT('Empno: ', Empno, ', Ename: ', Ename, ', Job: ', Job, ', MgrId: ', MgrId, ', DoB: ',
DoB, ', DoJ: ', DoJ, ', Sal: ', Sal, ', Comm: ', Comm, ', Deptno: ', Deptno)

INTO v_details

FROM Employee
WHERE Empno = p_Empno;

IF v_details IS NULL THEN

RETURN 'Employee not found';

ELSE

RETURN v_details;

END IF;

EXCEPTION

WHEN NO_DATA_FOUND THEN

RETURN 'Employee not found';

WHEN OTHERS THEN

RETURN 'Error occurred: ' || SQLERRM;

END;

-- Call the function with an Empno

SELECT GetEmployeeDetails(1); -- Replace 1 with the Empno you want to check

9. CREATE TABLE Employee (

Id INT PRIMARY KEY,

Name VARCHAR(100),

Basicpay DECIMAL(10,2),

DOB DATE,

Dept VARCHAR(100)

);

CREATE OR REPLACE PROCEDURE GeneratePayslip(

p_EmployeeId IN INT,

p_DA_percent IN DECIMAL,

p_HRA_percent IN DECIMAL,

p_TAX_percent IN DECIMAL,
p_DED_percent IN DECIMAL

) AS

v_BasicPay DECIMAL(10,2);

v_DA DECIMAL(10,2);

v_HRA DECIMAL(10,2);

v_TAX DECIMAL(10,2);

v_DED DECIMAL(10,2);

v_NetPay DECIMAL(10,2);

BEGIN

-- Retrieve basic pay of the employee

SELECT Basicpay INTO v_BasicPay FROM Employee WHERE Id = p_EmployeeId;

-- Calculate allowances and deductions

v_DA := v_BasicPay * (p_DA_percent / 100);

v_HRA := v_BasicPay * (p_HRA_percent / 100);

v_TAX := v_BasicPay * (p_TAX_percent / 100);

v_DED := v_BasicPay * (p_DED_percent / 100);

-- Calculate net pay

v_NetPay := v_BasicPay + v_DA + v_HRA - v_TAX - v_DED;

-- Print payslip

DBMS_OUTPUT.PUT_LINE('Employee Payslip for Employee ID: ' || p_EmployeeId);

DBMS_OUTPUT.PUT_LINE('-----------------------------------------------------');

DBMS_OUTPUT.PUT_LINE('Basic Pay: ' || v_BasicPay);

DBMS_OUTPUT.PUT_LINE('DA: ' || v_DA);

DBMS_OUTPUT.PUT_LINE('HRA: ' || v_HRA);

DBMS_OUTPUT.PUT_LINE('TAX: ' || v_TAX);

DBMS_OUTPUT.PUT_LINE('DED: ' || v_DED);

DBMS_OUTPUT.PUT_LINE('Net Pay: ' || v_NetPay);


END;

10. -- Create Voter table

CREATE TABLE Voter (

VoterId INT PRIMARY KEY,

Votername VARCHAR(100),

Gender VARCHAR(10),

Boothid INT,

Checkvote INT,

FOREIGN KEY (Boothid) REFERENCES Booth(Boothid)

);

-- Create Booth table

CREATE TABLE Booth (

Boothid INT PRIMARY KEY,

Location VARCHAR(255),

BIncharge VARCHAR(100)

);

-- a) (i) List the count of voters in each Booth

SELECT Boothid, COUNT(*) AS VoterCount

FROM Voter

GROUP BY Boothid;

-- (ii) List the count of Male voters voted

SELECT COUNT(*) AS MaleVotersVoted

FROM Voter

WHERE Gender = 'Male' AND Checkvote = 1;

-- b) Display the overall count of voters voted in the election


SELECT COUNT(*) AS TotalVotersVoted

FROM Voter

WHERE Checkvote = 1;

-- c) Display the Boothid, Location, and count of voters voted

SELECT b.Boothid, b.Location, COUNT(v.Checkvote) AS VotersVoted

FROM Booth b

LEFT JOIN Voter v ON b.Boothid = v.Boothid AND v.Checkvote = 1

GROUP BY b.Boothid, b.Location;

-- d) Write a function to return the percentage of poll in a booth when boothid is given as input.
Handle Exceptions

CREATE OR REPLACE FUNCTION CalculatePollPercentage(p_BoothId INT) RETURN DECIMAL


AS

v_TotalVoters INT;

v_VotersVoted INT;

v_Percentage DECIMAL;

BEGIN

SELECT COUNT(*) INTO v_TotalVoters FROM Voter WHERE Boothid = p_BoothId;

SELECT COUNT(*) INTO v_VotersVoted FROM Voter WHERE Boothid = p_BoothId AND
Checkvote = 1;

IF v_TotalVoters = 0 THEN

RETURN 0;

ELSE

v_Percentage := (v_VotersVoted / v_TotalVoters) * 100;

RETURN v_Percentage;

END IF;

EXCEPTION

WHEN NO_DATA_FOUND THEN

RETURN NULL;

WHEN OTHERS THEN


RETURN NULL;

END;

You might also like