Page 1 of 9
B.E / B.Tech./B.Arch. PRACTICAL END SEMESTER EXAMINATIONS, APRIL / MAY 2019
                                          Fourth Semester
            CS8481 & DATABASE MANAGEMENT SYSTEMS LABORATORY
                                         (Regulations 2017)
Time : 3 Hours               Answer any one Question                          Max. Marks 100
                          (To be filled by the question paper setter)
    Aim & Procedure            Queries &           Output &      Viva-Voce    Record      Total
                                Program             Result
            20                      30                 30                10     10         100
     1.    Consider the Insurance database given below.
                    PERSON(driver_ID, name, address)
                    CAR(regno, model,year )
                    ACCIDENT(report_number,accd_date,location)
                    OWNS(driver_id,regno)
                    PARTICIPATED(driver_id,regno,report_number,damage_amount)
                    create table person(driver_id number primary key, name varchar(10), address
                    varchar(25));
                    create table car(regno number primary key, model varchar(10),year number);
                    create table accident(report_number number primary key,accd_date
                    varcahr(10),location varchar(10));
                    create table owns(driver_id number,regno number)
                    create table participated(driver_id number,regno number,report_number
                    number,damage_amount number)
             i.      Specify the primary keys and foreign keys and enter at least five tuples for
                     each relation.
                     alter    table    owns     add    foreign    key(driver_id,regno)   references
                     person(driver_id),car(regno);
                     alter table participated add foreign key(driver_id,regno,report_no) references
                     person(driver_id),car(regno),accident(report_number);
             ii.     Update the damage amount for the car with specific regno in the accident
                     with report number 1025.
                     update participated set damage_amount=5000 where report_number=1025;
             iii.    Add a new accident to the database.
                     insert into accident(1001,'22-09-2020','trichy');
             iv.     Find the total number of people who owned cars that were involved in
                     accidents in the year 2018.
                                   Page 2 of 9
             ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY';
             select name from person natural join own where driver_id in (select driver_id
             from accident natural join participated where to_date(accd_date)>to_date('31-
             12-2017') and to_date(accd_date)>to_date('01-01-2019'));
       v.    Find the number of accidents in which cars belonging Wagon R were
             involved.
             select count(*) from participated where regno in (select regno from car where
             model='wagon r');
3.   Create the Company database with the following tables and do the following:
      Administration(employee_salary,     development _cost, fund_amount,
     turn_over,bonus)
      Emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no,
     salary).
     create    table     administration(employee_salary             int,development_cost
     int,fund_amount int, turn_over int,bonus int);
     insert into administration values(10000,2000,5000,1500,1500);
     insert into administration values(15000,3000,10000,1000,1000);
     create table emp_details(emp_no int, emp_name varchar(20), DOB
     varchar(10), address varchar(100), doj varchar(10), mobile_no numeric(10),
     dept_no numeric(4), salary int);
     insert     into      emp_details             values(1,'raju','2-6-1986','trichy','4-8-
     2020',9874672837,101,10000);
     insert    into     emp_details          values(2,'amala',24-5-1988,'chennai',2-8-
     2020,8738675386,102,15000);
     insert    into      emp_details             values(3,'arjun',20-8-2000,'trichy',7-10-
     2021,9374798425,101,10000);
      i.    Calculate the total and average salary amount of the employees of each
            department.
            select sum(salary) as tot_salary,avg(salary) as avg_salary from
            emp_details group by dept_no;
                                      Page 3 of 9
      ii.    Display total salary spent for employees.
             select sum(salary) as tot_sal from emp_details;
      iii.   Develop a PL/SQL function to display total fundamount spent by the
             administration department .
              declare
             f_sum number(10,2);
             begin
             select sum(fund_amount) into f_sum from administration;
             dbms_output.put_line('sum='||to_char(f_sum));
             end;
             /
4.   Create the student database with the following tables and do the
     following: assessment(reg_no,name, mark1, mark2, mark3, total)
     dept_details (dept_no, dept_name, location).
     create table assessment(reg_no number primary key,name varchar(25), mark1
     number, mark2 number, mark3 number, total number);
     insert into assessment values(1,'ragu',50,80,70,200);
     insert into assessment values(2,'jabbat',60,90,70,220);
     create table dept_details (dept_no number, dept_name varchar(25), location
     varchar(25));
       i.   Using alter command drop the column location from the
      table dept_details.
       alter table dept_details column location;
       insert into dept_details values(201,'cse');
       insert into dept_details values(202,'ece');
       ii.   Display all dept_name along with dept_no.
       select dept_no,dept_name from dept_details;
       iii. Drop the table dept_details.
       drop table dept_details;
      iv.    Write a PL/SQL Trigger to verify the data before insertion on assessment
             table.
              create trigger verify
             before insert
             on assessment
             for each row
             select * from assessment;
                                       Page 4 of 9
6.   Consider the following tables.
     SAILOR(sid, sname, rating, age)
     BOATS(bid, bname, colour)
     RESERVES(sid, bid, day)
     create table BOATS(bid number primary key, bname varchar(20), colour varchar(10));
     insert into BOATS values(201,'b1','blue');
     insert into BOATS values(202,'b2','green');
     insert into BOATS values(203,'b3','red');
     create table RESERVES(sid number, bid number, day varchar(3),foreign key(sid)
     references SAILOR(sid),foreign key(bid) references BOATS(bid));
     insert into RESERVES values(101,201,'sun');
     insert into RESERVES values(102,202,'mon');
     insert into RESERVES values(103,203,'tue');
     insert into RESERVES values(104,201,'wed');
       i.      List the sailors in the descending order of their rating.
               select sname from SAILOR order by rating desc;
       ii.     List the sailors whose youngest sailor for each rating and who can
               vote.
               select sname from sailor where age>=18 and age in (select
               min(age) from sailor group by rating);
       iii.    List the sailors who have reserved for both ‘RED’ and ‘GREEN’
               boats.
               select sname from SAILOR natural join RESERVES where bid in(select bid
               from BOATS where colour='red' or colour='green');
       iv.     Create synonym for sailor table.
               create synonym sailor_syn for SAILORS;
       v.      Create a PL / SQL Function that accepts SID and returns the name of
               sailor.
               create function Return_name(id number) return varchar(50) as
               declare
               name varchar(50);
               begin
               select sname into name from SAILOR where sid=id;
               dbms_output.put_line('name:'||name);
               end;
               /
               begin Return_name(102) end;
               /
                                     Page 5 of 9
7.   Consider the following relations for an order processing application:
     CUSTOMER (CID, NAME)
     PRODUCT (PCODE, PNAME, UNIT_PRICE)
     CUST_ORDER (OCODE, ODATE, CID)
     ORDER_PRODUCT (OCODE, PCODE, QTY)
     create table customer (cid number primary key, name varchar(10));
     create table product (pcode number primary key, pname varchar(10), unit_price
     number);
     create table cust_order (ocode number, odate varchar(10), cid number);
     create table order_product (ocode number, pcode number, qty number, foreign
     key(pcode,ocode) references product(pcode),cust_order(ocode));
     create sequence pcode_seq
     starts with 1
     increment by 1;
     update product set new.pcode=next value for pcode_sed;
     declare
     tot_amt number;
     cursor p is
     select pcode,qty from order_product;
     begin
     for product in p
     loop
     tot_amt:=tot_amt+product.qty*(select unit_price from product where
     pcode=product.pcode);
     end loop;
     dbms_output.put_line('tot:'||tot_amt);
     end;
     /
     create trigger check
     before insert
     on product
                                         Page 6 of 9
      for each row
      begin
      if new.pname not in (pen,pencil,eraser) then
      raise_application_error(-20001,'cannot insert');
      end if;
      end;
      /
          i.     Develop a Trigger to ensure the product to be Pen , Eraser, Pencil during
                 insertion
          ii.    Develop a PL/SQL Function to calculate the total cost of ordered product.
          iii.   Use Sequence for PCODE insertion in product table
10.   Consider the following database of student enrollment in courses and books adopted
      for that course.
      STUDENT(regno, name, major, bdate)
      COURSE(courseno, cname, dept)
      ENROLL(regno, courseno, sem, marks)
      create table student(regno number primary key, name varchar(10), major varchar(10),
      bdate date);
      create table course(courseno number primary key, cname varchar(10), dept
      varchar(10));
      create table enroll(regno number, courseno number, sem number(1), marks
      number,foreign key(regno,courseno) references student(regno),course(courseno));
          i.     Display the total number of students register for more than two courses in a
                 department specified.
                 select count(regno) from course natural join enroll group by courseno having
                 dept='cse' and count(courseno)>2;
          ii.    Display the students who have secured the highest mark in each course
                 select name from student where regno in (select regno from enroll
                 where mark =max(mark));
          iii.   List the youngest student of each course in all departments.
          iv.    Develop PL/SQL Cursor that selects marks of a particular student in a
                 specified semester.
                  declare cursor s for select mark from enroll where regno=101 and
                 sem=3;
11.
      The following are maintained by a book dealer.
      AUTHOR(author_id, name, city, country)
      PUBLISHER(publisher_id, name, city, country)
      CATALOG(book_id, title, author_id, publisher_id , category_id, year, price)
                                Page 7 of 9
CATEGORY(category_id, description)
ORDER_DETAILS(order_no, book_id, quantity)
create table author(author_id number primary key, name varchar(10), city varchar(10),
country varchar(10));
create table publisher(publisher_id number primary key, name varchar(10), city
varchar(10), country varchar(10));
create table category(category_id number primary key, description varchar(10));
create table catalog(book_id number primary key, title varchar(10), author_id number,
publisher_id number, category_id number, year number, price number, foreign
key(author_id,publisher_id,category_id) references
author(author_id),publisher(publisher_id),category(category_id));
create table order_details(order_no number primary key, book_id number foreign key
references catalog(book_id), quantity number);
 i.     List the author of the book that has minimum sales.
        select name from author natural join catalog where book_id in (select book_id
        from order_details where quantity=min(quantity));
 ii.    Display total number of books in each category.
        select category_id,count(category_id) from catolog where group by
        category_id;
 iii.   Develop a PL/SQL procedure that updates the price of the book by 10%
        those with maximum sales.
        create procedure price_increase as
        declare
        bookid number;
        begin
        select book_id into bookid where quantity=max(quantity);
        update catalog set price=price+(price*0.10) where book_id=bookid;
        commit;
        end;
        /
        begin price_increase end;
        /
                                         Page 8 of 9
12.   Create the student database with the following tables and do the
      following: mark_details(reg_no,name, mark1, mark2, mark3, total)
      dept_details (dept_no, dept_name, HOD)
      stud_details(reg_no,name, dob, address)
      create table mark_details(reg_no number,name varchar(10), mark1 number,
      mark2 number, mark3 number, total number);
      create table dept_details (dept_no number, dept_name varchar(5), HOD
      varchar(10));
      create table stud_details(reg_no number,name varchar(10), dob varchar(10),
      address varcahr(50));
       i.        Using alter command to assign foreign key in mark_details.
                 alter table mark_details add foreign key(reg_no) references
                 stud_details(reg_no);
       ii.       Display the address of the students who have secured the top three ranks.
                 select name,address from stud_details natural join mark_details order by total
                 desc limit 3;
       iii.      Write a PL/SQL procedure to update the grade according to the marks
                 secured.
                  declare
                 mark number;
                 begin
                 select total into mark from mark_details where reg_no=;
                 if mark>=90 then
                 dbms_output.put_line('A');
                 elseif mark>=80 and mark <90 then
                 dbms_output.put_line('B');
                 else
                 dbms_output.put_line('fail')
                 /
15.   Create a database for Placement and Training cell.
      Stud_details(regno, name, dept, percentage)
      Company(companyID,name, noOfVacancy)
      Training_Details(CourseID, name, Trainer)
      Placed(regno, companyID,minSal)
      create table stud_details(regno number, name varchar(10), dept varchar(5), percentage
      number);
      create table company(companyID number,name varchar(10), noOfVacancy number);
      create table training_Details(CourseID number, name varchar(10), Trainer varchar(10));
      create table placed(regno number, companyID number,minSal number);
            i.     List the students who are eligible for recruitment in a particular company.
                               Page 9 of 9
select name from stud_details where percentage>=60;
   ii.     Display the student who has been placed with highest salary
           select name from stud_details where regno in (select regno from
           where minsal=max(minsal));
 iii.   Develop a PL/SQL exception that provides an alternate for not eligible
        students.