0% found this document useful (0 votes)
2 views

Database Lab

The document outlines a series of SQL and PL/SQL tasks for various database schemas including Library, College, Order, Departments, Election Commission, and Airline Flight information. It includes writing SQL queries for data retrieval, manipulation, and creating views, as well as developing stored procedures and triggers. Additionally, it involves tasks related to cursor operations and fine calculations for book borrowing scenarios.

Uploaded by

madhudqm789
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Database Lab

The document outlines a series of SQL and PL/SQL tasks for various database schemas including Library, College, Order, Departments, Election Commission, and Airline Flight information. It includes writing SQL queries for data retrieval, manipulation, and creating views, as well as developing stored procedures and triggers. Additionally, it involves tasks related to cursor operations and fine calculations for book borrowing scenarios.

Uploaded by

madhudqm789
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSPC2204 DATABASE ENGINEERING LAB (0-0-3)

1.​ Consider the following schema for a Library Database:


BOOK (Book_id, Title, Publisher_Name, Pub_Year) BOOK_AUTHORS (Book_id,
Author_Name) PUBLISHER (Name, Address, Phone)
BOOK_COPIES (Book_id, Programme_id, No-of_Copies)
BOOK_LENDING (Book_id, Programme_id, Card_No, Date_Out, Due_Date)
LIBRARY_PROGRAMME (Programme_id, Programme_Name, Address)
​ Write SQL queries to:
•​ Retrieve details of all books in the library – id, title, name of publisher, authors,
number of copies in each Programme, etc.
•​ Get the particulars of borrowers who have borrowed more than 3 books, but from
Jan 2025 to Jun 2025.
•​ Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulation operation.
•​ Partition the BOOK table based on year of publication. Demonstrate its working
with a simple query.
•​ Create a view of all books and its number of copies that are currently available in the
library.​

2.​ Consider the schema for College Database:


​ STUDENT (REGNO, SName, Address, Phone, Gender) SEMSEC (SSID, Sem, Sec)
​ CLASS (REGNO, SSID)
​ COURSE (Subcode, Title, Sem, Credits)
​ IAMARKS (REGNO, Subcode, SSID, Test1, Test2, Test3, FinalIA)
​ Write SQL queries to:
•​ List all the student details studying in fourth semester ‘C’ section.
•​ Compute the total number of male and female students in each semester and in each
section.
•​ Create a view of Test1 marks of student REGNO ‘1BP22CS101’ in all Courses.
•​ Calculate the FinalIA (average of best two test marks) and update the corresponding
table for all students.
Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’ If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.​

3.​ Consider the following schema for Order Database:


​ SALESMAN (Salesman_id, Name, City, Commission)
​ CUSTOMER (Customer_id, Cust_Name, City, Grade, Salesman_id)
​ ORDERS (Ord_No, Purchase_Amt, Ord_Date, Customer_id, Salesman_id)
​ Write SQL queries to :
•​ Count the customers with grades above Bangalore’s average.
•​ Find the name and numbers of all salesman who had more than one customer.​
•​ List all the salesman and indicate those who have and don’t have customers in their
cities (Use UNION operation.)
•​ Create a view that finds the salesman who has the customer with the highest order of
a day.
•​ Demonstrate the DELETE operation by removing salesman with id 1000. All his
orders must also be deleted.​

4.​ Consider the following tables namely “DEPARTMENTS” and “EMPLOYEES” Their
schemas are as follows,
​ Departments (dept _no, dept_ name, dept_location); Employees (emp_id, emp_name,
emp_salary, dept_no);
•​ Develop a query to grant all privileges of employees table into departments table
•​ Develop a query to grant some privileges of employees table into departments table
•​ Develop a query to revoke all privileges of employees table from departments table
•​ Develop a query to revoke some privileges of employees table from departments
table
•​ Write a query to implement the save point.​

5.​ Using the tables “DEPARTMENTS” and “EMPLOYEES” perform the following
queries
•​ Display the employee details, departments that the departments are same in both the
emp and dept.
•​ Display the employee’s name and Department name by implementing a left outer
join.
•​ Display the employee’s name and Department name by implementing a right outer
join.
•​ Display the details of those who draw the salary greater than the average salary.​

6.​ Consider the schema for Election Commission:


​ CONSTITUENCY (cons_id, csname, csstate, no_of_voters) PARTY (pid, pname,
psymbol);
​ CANDIDATES (cand_id, name, age, state, phone_no); VOTER (vid, vname, vage,
vaddr)
​ Queries:
•​ List the details of the candidates who are contesting from more than one
constituency which belongs to different states.
•​ Display the state name having maximum number of constituencies.
•​ Create a stored procedure to insert the tuple into the voter table by checking the
voter’s age. If voter’s age is at least 18 years old, then insert the tuple into the voter
else display the message “Not an eligible voter”.
•​ Create a stored procedure to display the number_of_voters in the specified
constituency, where the constituency name is passed as an argument to the stored
procedure.
•​ Create a TRIGGER to UPDATE the count of “Number_of_voters” of the respective
constituency in “CONSTITUENCY” table, AFTER inserting a tuple into the
“VOTER” table.​

7.​ Consider the following relations containing airline flight information: FLIGHTS (flno,
distance, departs, arrives)
​ AIRCRAFT (aid, aname, cruisingrange) CERTIFIED (eid, aid)
​ EMPLOYEES (eid, ename, salary)​
​ Note that the Employees relation describes pilots and other kinds of employees as well;
every pilot is certified for some aircraft (otherwise, he or she would not qualify as a
pilot), and only pilots are certified to fly.

​ Write the following queries in relational algebra, tuple relational calculus, and domain
relational calculus.
•​ Find the eids of pilots certified for some Boeing aircraft.
•​ Find the names of pilots certified for some Boeing aircraft.
•​ Find the aids of all aircraft that can be used on non-stop flights from DELHI TO
MUMBAI.
•​ Identify the flights that can be piloted by every pilot whose salary is more than
$100,000. (Hint: The pilot must be certified for at least one plane with a sufficiently
large cruising range.)
•​ Find the names of pilots who can operate some plane with a range greater than 3,000
miles but are not certified on any Boeing aircraft.
•​ Find the eids of employees who make the highest salary.
•​ Find the eids of employees who make the second highest salary.
•​ Find the eids of pilots who are certified for the largest number of aircraft.
•​ Find the eids of employees who are certified for exactly three aircraft.
•​ Find the total amount paid to employees as salaries.​

8.​ Create cursor for Employee table & extract the values from the table. Declare the
variables, Open the cursor & extract the values from the cursor. Close the cursor.
​ Employee (E_id, E_name, Age, Salary)​

9.​ Write a Stored Procedure namely proc_Grade for the categorization of student. If marks
scored by students in examination is <=1500 and marks>=990 then student will be
placed in distinction category if marks scored are between 989 and900 category is first
class, if marks 899 and 825 category is Higher Second Class.
​ Write a PL/SQL block for using procedure created with above requirement.
Stud_Marks (name, total_marks)
​ Result (Roll, Name, Class)
​ Frame the separate problem statement for writing PL/SQL Stored Procedure and
function, inline with above statement. The problem statement should clearly state the
requirements.​

10.​ Write a PL/SQL block of code for the following requirements: Schema:
​ Borrower (Rollin, Name, Date_of_Issue, Name_of_Book, Status)
​ Fine (Roll_no, Date, Amt)
•​ Accept roll_no & name of book from user.
•​ Check the number of days (from date of issue), if days are between 15 to 30 then
fine amount will be Rs 5per day.
•​ If no. of days>30, per day fine will be Rs 50 per day & for days less than 30, Rs.
5per day.
•​ After submitting the book, status will change from I to R.
•​ If condition of fine is true, then details will be stored into fine table.
Frame the problem statement for writing PL/SQL block inline with above statement.
​ NOTE: Use Control structure and Exception handling.​

You might also like