DBMS Lab - Question Set
DBMS Lab - Question Set
10. Create the following table with the mapping given below.
book (bookid, book_name,author_name,price,quantity).
Student(sid, bookid, deptname)
(i) write a query to update the quantity by double in the table book.
(ii)List all the book_name whose price is greater than Rs.400.
(iii)Retrieve the list of author_name whose first letter is ’a’ along with the book_name and price.
(iv) Create a view which display all the book taken by particular student.
(v) Write a pl/sql program to swap two numbers.
11. Create the following table with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Find the name of the student whose reg_no is’107’.
(ii)Display the details of a particular student whose name is ‘MATHU’.
(iii)Rename the table mark_details as ’academics’.
(iv) Create a view which contain student name and total marks.
(v) Write a pl/sql program to find the sum & avg marks of all the student using procedures.
12. Create the following tables with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Alter the table mark_details to add a column average with data type as long.
(ii) Display the months between the DOB and till date.
(iii) Using alter command drop the column address from the table stu_details.
(iv) Find the average of all marks.
(v) Write a pl/sql program to find the sum & avg marks of all the student using procedures.
13. Create the following tables with the mapping given below.
a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i) Display the months between the doj and till date.
(ii) Alter the table emp_details to add a primary key constraint on emp_no.
(iii) Display the employee from Chennai and whose name start with ‘A’.
(iv) Find the total employee in each department.
(v)Write a pl/sql program to display the salary of a particular employee using functions.
14. Create the following tables with the mapping given below.
a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i). Create a view emp1 from emp_details such that it contains only emp_no and emp_name.
(ii) Select dept_no from dept_details and not in emp_details using both the tables.
II. Create a table named as student and insert values into the table.
III. Create the following table with the mapping given below.
Book(book_name,author,price,quantity).
(iii)Write a query to update the quantity by double in the table book.
Write a PL/SQL program to find the greatest of 3 numbers.
15. Create the following tables with the mapping given below.
a. assessment(reg_no,name, mark1, mark2, mark3, total)
b.dept_details (dept_no, dept_name, location).
(i) Using alter command drop the column location from the table dept_details.
(ii) Display all dept_name along with dept_no.
(iii)Drop the table dept_details.
(iv) Find the average of the marks.
(v)Write a pl/sql program to find the sum & avg marks of all the student using procedures.
16. Create the following tables with the mapping given below.
a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i)Select dept_no from dept_details and not in emp_details using both the tables.
(ii)Display the structure of the table emp_details.
(iii)Display the emp_name getting highest salary
(iv) Create a view which displays the dept_name and emp_name.
(v)Creating Trigger On Table Employ for Not Allowing Insert/Update/Delete Operations On
Friday.
17. Create the following table with the mapping given below.
retailor (Cust_id, Cust_name, place, ph_no,pan_no).
Review(Cust_id, productid,comment)
Pdt(pdtid,pdtname)
(i) Alter the table to add a column pin_no.
(ii) Display the details of customer who are all living in bangalore.
(iii) Display the customer name whose first letter is ‘M’.
(iv) Create a view that contain productname, custname, and review comment.
(v) Create a Function to find the area of Circle.
18. Create the following table with the mapping given below.
a.Product_master(product_name,purchase_prize,sell_prize,profit,quantity,balance)
b. Customer (Cust_id, Cust_name, Addr, ph_no,pan_no).
(i)Display all the customer names along with their address.
(ii)Drop the table customer.
(iii) Change the sell_price to 5000& purchase_price amount to 4000 for any one of the product in product_master.
(v) Create a trigger to update the balance in product_ master table whenever transaction table will have a new entry.
19. Create the following table with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i)Find out the name of all students along with their total marks.
(ii)Change the mark1 as ‘78’ from ‘59’ and alter the total for a particular student.
(iii) Delete all the records and its memory space from the table student.
(iv) Create a view with total mark and student name.
(v) Write a pl/sql program to check whether the given number is prime or not.
20. Create the following table with the mapping given below.
a.Administration(employee_salary, development _cost, fund_amount, turn_over,bonus)
b. Emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
(i)Calculate the total and average salary amount of the administration table.
(ii)Display total salary spent for employees.
(iii)Display total fundamount.
(iv) Create a view with bonus and emp_name.
(v)write a pl/sql code block to calculate the area & circumference of a circle.
21. Create the following table with the mapping given below.
emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
Dept(deptno, deptname)
Deptname should have values HR, Admin, Teaching, Non-Teaching
(i)List all employees which starts with either B or C.
(ii)Display the names and dob of all employees who were born in Feburary.
(iii)List out the employee names whose salary is greater than 15000.
(iv) Find the empname with highest salary.
(iv)Write a pl/sql program to find the sum of 1-100 numbers.
22. Create the following tables with the mapping given below.
a. Customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
b. Loan (Loan_id, Amount, Interest, Cust_id,branch)
(i)Display the entire loan relation in descending order of the amount.
(ii)Find the names of all branches in loan relation.
(iii)Find all customer id's for loan's with loan amount between 5000 and 15000.
(iv)write a database trigger after insert for each row add interest Rs.500 on table Loan if the Loan amount is greater than
5,00,000.
23. Consider the following relations for a boat management application for a beach resort:
SAILOR (SID, NAME, DOB, GENDER, RATING)
RATING can take the vales (‘FAIR’,’GOOD’,’EXCELLENT’) BOAT (BID, BTYPE, BNAME,
COLOR)
BTYPE can take two values (D, S) D – Deluxe
S –Super Deluxe
SAILS (SID, BID, DOT, SHIFT)
DOT – Date of Trip
SHIFT can take two values – FN or AN
A sailor is assigned a boat on a day. A sailor is permitted to sail the boat for only one shift on a day. The primary keys are
underlined. Identify the foreign keys.
a. Develop DDL to implement the above Schema specifying appropriate data types for each attribute and enforcing
primary key, check constraint and foreign key constraints.
b. Populate the database with a rich data set.
c. Develop a SQL query to list the details of boats whose type is Super Deluxe and Color is Red.
d. Develop a SQL query to list the details of sailors who have sailed on the same boat more than four times.
e. Develop a view that will keep track of sailor id, sailor name, date of trip, boat id, boat type, boat name and shift.
f. Create a procedure which accepts a sid and displays the sailor name and rating records.
24. Consider the following relations for a transport management system application:
DRIVER (DCODE, DNAME, DOB, GENDER)
CITY (CCODE, CNAME)
TRUCK (TRUCKCODE, TTYPE)
25. Consider the following relational schema for a banking database application: CUSTOMER (CID, CNAME)
BRANCH (BCODE, BNAME)
a. Implement the above schema enforcing primary key and foreign key constraints.
b. Develop a SQL query to list the details of branches where the number of accounts is less than the average number of
accounts in all branches.
26. Consider the following relations for an order-processing database application in a company:
CUSTOMER (CUSTOMERNO VARCHAR2 (5), CNAME VARCHAR2 (30), CITY VARCHAR2 (30))
Implement a check constraint to check CUSTOMERNO starts with ‘C’ CUST_ORDER (ORDERNO
VARCHAR2 (5), ODATE DATE, CUSTOMERNO
REFERENCES CUSTOMER, ORD_AMT NUMBER (8))
Implement a check constraint to check ORDERNO starts with ‘O’
ITEM (ITEMNO VARCHAR2 (5), ITEM_NAME VARCHAR2 (30),
UNIT_PRICE NUMBER (5))
Here, ORD_AMT refers to total amount of an order (ORD_AMT is a derived attribute); ODATE is the date the order was
placed; SHIP_DATE is the date an order is shipped. The primary keys are underlined.
a. Develop DDL to implement the above Schema enforcing primary key, check constraints and foreign key
constraints.
b. Populate the database with a rich data set.
c. Develop a SQL query to list the details of customers who have placed more than three orders.
d. Develop an update statement to update the value of ORD_AMT attribute in CUST_ORDER relation.
e. Create a view that will keep track of the details of each customer and the number of orders placed.
f. Develop a database trigger that will not permit to insert more than six records in the CUST_ORDER relation for a
particular order. (An order can contain a maximum of six items).
27. Consider the following relations for an order-processing database application in a company:
CUSTOMER (CUSTOMERNO VARCHAR2 (5), CNAME VARCHAR2 (30), CITY VARCHAR2 (30))
Implement a check constraint to check CUSTOMERNO starts with ‘C’ CUST_ORDER (ORDERNO
VARCHAR2 (5), ODATE DATE, CUSTOMERNO
REFERENCES CUSTOMER, ORD_AMT NUMBER (8))
Implement a check constraint to check ORDERNO starts with ‘O’
ITEM (ITEMNO VARCHAR2 (5), ITEM_NAME VARCHAR2 (30),
UNIT_PRICE NUMBER (5))
Here, ORD_AMT refers to total amount of an order (ORD_AMT is a derived attribute); ODATE is the date the order was
placed; SHIP_DATE is the date an order is shipped. The primary keys are underlined.
a. Develop DDL to implement the above Schema enforcing primary key, check constraints and foreign key
constraints.
b. Populate the database with a rich data set.
c. Develop a SQL query to list the details of items whose price is less than the average price of all items.
d. Develop a SQL query to list the order number and number of items in each order.
e. Develop an update statement to update the value of ORD_AMT attribute in CUST_ORDER relation.
f. Create a view that will keep track of the details of each customer and the number of orders placed.
g. Develop a database trigger that will not permit to insert more than six records in the CUST_ORDER relation for a
particular order. (An order can contain a maximum of six items).
28. Consider the following relational schema for a banking database application: CUSTOMER (CID, CNAME)
a. Develop DDL to implement the above Schema specifying appropriate data types for each attribute enforcing primary
key, check constraints and foreign key constraints.
c. Develop a SQL query to list the details of customers who have balance less than the average balance of all customers.
d. Develop a SQL query to list the details of customers who have performed three transactions on a day.
e. Create a view that will keep track of customer details and the number of accounts each customer has.
f. Develop a database trigger that will not permit a customer to perform more than three transactions on a day.
29. Consider the following relational schema for a library management system:
c. Develop a SQL query to list the details of authors who have authored more than three books.
d. Develop a SQL query to list the details of borrowers who do not have any books checked out.
e. Develop a SQL query to list the details of borrowers who have more than five books checked out.
f. Create a view that will keep track of the card number, card holders name and number of books borrowed (Number
of books with status ‘T’).
g. Develop a database trigger that will not permit a borrower to borrow a book if there are three books borrowed by the
borrower with status ‘T’ (A borrower can borrow a maximum of five books).