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

DBMS Lab - Question Set

Uploaded by

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

DBMS Lab - Question Set

Uploaded by

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

1. 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). Display only those rows whose total ranges between 250 and 300.
(ii). Drop the table mark_details.
(iii). Delete the row whose reg_no=161.
(iv). Display all details whose names begins with 'a'.
(v) Use the Control Structure IF-THEN-ELSE to print Remarks on the Marks Secured by
the Student.

2.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) Truncate the table dept_details.
(ii) Find the name of employees who works in “HR”department.
(iii) Conut the number of employees in each department.
(iv) Display the emp_name getting highest salary.
(v) Write a database trigger before insert for each row adding Rs.100 on table salary if the age is below 18.

3. Create the following tables with the mapping given below.


a. book (book_name,author,price,quantity,cust_id).
b. customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
(i) Truncate the table customer.
(ii) List the author of the book which one have the price of 200.
(iii).List the price of the book which one is between the price of 175 & 250.
(iv).Retrieve all the details from the table book whose author name start with K.
II.Write a pl/sql program to find the largest of two numbers.

4. Create the following tables with the mapping given below.


a. stu_details (reg_no, stu_name, DOB, address, city,deptname)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i)Find out the name of all students.
(ii)List all the student detail that who are all located in Chennai.
(iii) Drop the table mark_details.
(iv) Display all details whose names begins with 'S'.
(v)Use the Conditional statement CASE to print Department Name from Student Register
number.
5. 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)
(i)Display the Cust_name having both Loan and Account .
(ii) Display number of Loans, the sum of Loan Amount of a ParticularCustname(“LEENA”)
(iii)Display the Custname doesn’t hold any Account nor taken any Loan
(iv)Add a column nol(number of loans)
(v)Write a pl/sql program to find the address of a particular customer using functions.

6. 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) Create a table named as student and insert values into the table.
(iii) Write a pl/sql program to display the salary of a particular employee using functions.
(iv) Create a view with emp_no emp_name and dept_name.
(v) Write PL/SQL Program to generate even numbers.

7. Create the following tables with the mapping given below.


Phone_book(ph_no,door_no,street,place).
Customer (custname, ph_no)
(i)Display all names along with ph_no.
(ii)Add a column pin_no.
(iii) Create a view with ph_no and custname for all customer.
(iv) Display the phone number from a particular street.
(v)Write a pl/sql program to find the factorial of a given number using functions.

8. Create the following tables with the mapping given below.


emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, salary).
Dept(deptname, deptno,emp_no)
(i)Develop an SQL query to find the employee with highest Salary.
(ii)Drop the column salary by altering the table.
(iii)Rename the table as ’Employee’.
(iv) Create a savepoint for the table dept.
(v) Write a pl/sql program to find the address of a particular customer using functions.
9. Create the following table with the mapping given below.
Customer (Cust_id, Cust_name, Addr, ph_no,pan_no).
(i)Delete the row where cust_name=’NANCY’.
(ii)Update the addr where cust_name=’MATHIK’.
(iii)Display the details of a customer named ‘LITHUANA’.
(iv) Write a pl/sql program to swap two numbers.
(v) Write a pl/sql program to find the summation of odd numbers using for loop.

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)

TTYPE can take two values (‘L’,’H’) L-Light, H- Heavy


Each truck is assigned a unique truck code. There can be many trucks belonging to the same truck type.
DRIVE_TRUCK (TRUCKCODE, DCODE, DOT, CCODE)

DOT – Date of Trip


The primary keys are underlined. Identify the foreign keys.
a. Implement the above schema enforcing primary key and foreign key constraints.
b. Develop an SQL query to list the details of each driver and the number of trips traveled.
c. Develop an SQL query to find the driver who have used the truck more than 2 times.
d. Develop an SQL query to find the Female driver.
e. Develop a view that will keep track of (TRUCKCODE, DCODE, DOT, DNAME).

25. Consider the following relational schema for a banking database application: CUSTOMER (CID, CNAME)
BRANCH (BCODE, BNAME)

ACCOUNT (ANO, ATYPE, BALANCE, CID, BCODE)


An account can be a savings account or a current account. Check ATYPE in ‘S’ or ‘C’. A customer can have both types of
accounts.
TRANSACTION (TID, ANO, TTYPE, TDATE, TAMOUNT) TTYPE CAN BE ‘D’ OR ‘W’
D- Deposit; W – Withdrawal
The primary keys are underlined. Identify the foreign keys.

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.

c. Update the account balance of customer “Ajay”.


d. Develop an SQL query to group customer based on account type.
e. Develop a view that will keep track of (ANO, CID, CNAME, BALANCE).

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))

Implement a check constraint to check ITEMNO starts with ‘I’

ORDER_ITEM (ORDERNO REFERENCES CUST_ORDER, ITEMNO

REFERENCES ITEM, QTY NUMBER (3))


SHIPMENT (ORDERNO REFERENCES CUST_ORDER, ITEMNO

REFERENCES ITEM, SHIP_DATE DATE)

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))

Implement a check constraint to check ITEMNO starts with ‘I’

ORDER_ITEM (ORDERNO REFERENCES CUST_ORDER, ITEMNO

REFERENCES ITEM, QTY NUMBER (3))


SHIPMENT (ORDERNO REFERENCES CUST_ORDER, ITEMNO

REFERENCES ITEM, SHIP_DATE DATE)

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)

ACCOUNT (ANO, ATYPE, BALANCE, CID)


An account can be a savings account or a current account. Check ATYPE in ‘S’ or ‘C’. A customer can have both types of
accounts.
TRANSACTION (TID, ANO, TTYPE, TDATE, TAMOUNT) TTYPE CAN BE ‘D’ OR ‘W’
D- Deposit; W – Withdrawal The primary keys are
underlined.

a. Develop DDL to implement the above Schema specifying appropriate data types for each attribute 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 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:

BOOK (BOOKID, TITLE, PUBLISHERCODE, NO_OF_COPIES)


PUBLISHER (PUBLISHERCODE, PUBLISHER_NAME)
AUTHOR (AUTHORID, AUTHOR_NAME) BOOK_AUTHOR
(BOOKID, AUTHORID) BORROWWER (CARDNO, NAME)

BOOK_LOAN (BOOK_ID, CARDNO, DATEOUT, DUEDATE, STATUS)

Implement a Check Constraint for STATUS (‘R’ – Returned, ‘T’ – To be returned)


a. Develop DDL to implement the above Schema specifying appropriate data types for each attribute 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 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).

30. Consider the following relational schema:

STAFF (STAFFNO, NAME, DOB, GENDER, DOJ, DESIGNATION,


BASIC_PAY, DEPTNO)
GENDER must take the Value ‘M’ or ‘F’ DEPT (DEPTNO,
NAME)

SKILL (SKILL_CODE, DESCRIPTION, CHARGE_OUTRATE) STAFF_SKILL (STAFFNO ,


SKILL_CODE)

PROJECT (PROJECTNO, PNAME, START_DATE, END_DATE,


BUDGET, PROJECT_MANAGER_STAFFNO)
WORKS (STAFFNO, PROJECTNO, DATE_WORKED_ON, IN_TIME, OUT_TIME)

The Primary Keys are underlined.


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 department number and number of staff in each department.
d. Develop a SQL query to list the details of staff who earn less than the average basic pay of all staff.
e. Develop a SQL query to list the details of staff who have more than three skills.
f. Create a view that will keep track of the department number, the department name, the number of employees in the
department, and the total basic pay expenditure for each department.
g. Develop a database trigger that will not permit a staff to work on more than three projects on a day.

You might also like