Database Lab
Database Lab
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.
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.