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

RDBMS Sample Questions

This document contains 17 tasks involving creating database tables, inserting records, writing queries, stored procedures, functions and triggers. The tasks cover concepts such as joins, aggregation, sorting, conditional logic, exception handling and more. Tables are created for customers, salespeople, orders, hospitals, banks, employees, products, suppliers and more. Queries retrieve, insert, update, delete and manipulate data in the tables. Stored procedures and functions perform calculations. Triggers automatically update tables in response to data changes.

Uploaded by

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

RDBMS Sample Questions

This document contains 17 tasks involving creating database tables, inserting records, writing queries, stored procedures, functions and triggers. The tasks cover concepts such as joins, aggregation, sorting, conditional logic, exception handling and more. Tables are created for customers, salespeople, orders, hospitals, banks, employees, products, suppliers and more. Queries retrieve, insert, update, delete and manipulate data in the tables. Stored procedures and functions perform calculations. Triggers automatically update tables in response to data changes.

Uploaded by

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

1.

Create a table customer (cust_novarchar(5), cust_namevarchar(15), age number, phone varchar(10) )


a) insert 5 records and display it
b) add new field d_birth with date datatype
c) create another table cust_phone with fields cust_name and phone from customer table
d) remove the field age
e) change the size of the cust_name to 25
f) delete all the records from the table
g) rename the table cutomer to cust
h) drop the table
2. Create a table sales_man (salesman_no primary key, s_name not null, place, phone unique)
Create table sales_order(order_no primary key
order_date not null
salesman_no foreign key references salesman_no in sales_man
del_type values should be either P or F (check constraints)
order_status values should be 'Inprocess','Fullfilled','Backorder', 'Cancelled' (check constraints) )
a) Insert few records in both tables
b) Delete primary key from sales_man table
c) Delete Foreign key and Check constraints from sales_order table
d) Add primary key in sales_man using ALTER TABLE
e) Add foreign key and CHECK constraints in sales_order table using ALTER TABLE
3. Create a table Hospital with the fields (doctorid,doctorname,department,qualification,experience).
Write the queries to perform the following.
a) Insert 5 records
b) Display the details of Doctors
c) Display the details of doctors who have the qualification ‘MD’
d) Display all doctors who have more than 5 years experience but do not have the qualification
‘MD’
e) Display the doctors in ‘Skin’ department
f) update the experience of doctor with doctored=’D003’ to 5
g) Delete the doctor with DoctorID=’D005’
4. Create the following tables
Bank_customer (accno primary key, cust_name,place)
Deposit (accno foreignkey, deposit_no, damount)
Loan (accno foreign key loan_no, Lamount)
Write the following queries
a) Display the details of the customers
b) Display the customers along with deposit amount who have only deposit with the bank
c) Display the customers along with loan amount who have only loan with the bank
d) Display the customers they have both loan and deposit with the bank
e) Display the customer who have neither a loan nor a deposit with the bank
5. Create a table employee with fields (EmpID, EName, Salary, Department, and Age). Insert some
records. Write SQL queries using aggregate functions and group by clause
A. Display the total number of employees.
B. Display the name and age of the oldest employee of each department.
C. Display the average age of employees of each department
D. Display departments and the average salaries
E. Display the lowest salary in employee table
F. Display the number of employees working in purchase department
G. Display the highest salary in sales department;
H. Display the difference between highest and lowest salary
6. Create a table product with the fields (Product_code primary key, Product_Name, Category, Quantity,
Price).
Insert some records Write the queries to perform the following.
a. Display the records in the descending order of Product_Name
b. Display Product_Code, Product_Name with price between 20 and 50
c. Display the details of products which belongs to the categories of ‘bath soap’, ‘paste’, or
‘washing powder’
d. Display the products whose Quantity less than 100 or greater than 500
e. Display the products whose names starts with 's'
f. Display the products which not belongs to the category 'paste'
g. Display the products whose second letter is 'u' and belongs to the Category 'washing powder'
7. Consider the employee database given below. Give an expression in SQL for each of the following
queries:
EMPLOYEE (Employee-Name, City)
WORKS (Employee-Name, Company-Name, Salary)
COMPANY (Company-Name, City)
MANAGES (Employee-Name, Manager-Name)
A) Find the names of all employees who work in Infosys
B) Find the names and cities of residence of all employees who works in Wipro
C) Find the names, and cities of all employees whowork in Infosys and earn more than Rs. 10,000.
D) Find the employees who live in the same cities as thecompanies for which they work.
E) Find all employees who do not work inWipro Corporation.
F) Find the company that has the most employees.
8. Create table supplier(supcode,sname,city)
Create table product (pcode,pname)
Create table supl_product(supcode,pcode,qty)
a) Get all pairs of supplier numbers such that the two suppliers are located in the samecity.
b) Get supplier names for suppliers who supply product P2.
c) Get product numbers supplied by more than one supplier.
d) Get supplier numbers for suppliers who are located in the same city as supplier S1.
e) Get supplier names for suppliers who supply part P1.
f) Get the number of Suppliers, who are supplying at least one product.
g) For each product supplied, get the pcode. and the total quantity supplied for that part.
9. Prepare a salary report of the employees showing the details such as:
EmpNo, Name, Basic Pay, DA, Gross Salary, PF, Net Salary, Annual Salary and Tax
For this purpose, create a table named SALARIES having the following structure.

Field Name Type Width


EmpNo Character 10

Name Character 20
Basic Numeric 6

Enter the records of at least 10 employees. Use the following information for calculating the details
for the report:

DA is fixed as the 40% of the basic pay.


PF is fixed as 10% of the basic pay.
Gross Salary is (Basic Pay + DA).
Net Salary is (Gross Salary – PF)
Annual Salary is (12 * Net Salary)

Tax is calculated using the following rules:

If annual salary is less than 100000, No Tax


If annual salary is greater than 100000 but less than or equal to 150000, then the tax is 10% of the
excess over 100000.
If annual salary is greater than 150000 but less than or equal to 250000, then the tax is 20% of the
excess over 150000.
If annual salary is greater than 250000, then the tax is 30% of the excess over 250000.
10. Create table exam_result(rollno, avg_score, Grade) insert 10 records. Assign null values to the field
grade. Write Program block to update the grade field by using the following condition.

avg_score between 90 and 100 - A


avg_score 75 -89 - B
avg_score 60- 74 - C
avg_score 50 -59 - D
avg_score below 50 - E

11. Write a program code to calculate the area of a circle for a value of radius varying from 3 to 7. Store the
radius and the corresponding value of calculated area in an empty table named areas with field’s radius
and area.
12. Write a program block to calculate the electricity bill by accepting cust_no and units_consumed.
13. Create a procedure toprint Fibonacci number up to a limit, limit is passed as an argument
14. Create a function to check whether a given number is prime or not
15. create a table stud_mark(regno, sname ,avg_mark)
Insert few records
Write a procedure to display number of students got Distinction, first-class,second class , third class
or failed (90-100 distinction, 75-89firstclass60-74 second class 50-59 Third class below 50 failed)
16. create a table emp_salary(empno,enamedept,salary)
Write a function to return the average salary of a particular department by accepting departmentname
as argument.
17. create a table Student(regno, sname, sub1,sub2,sub3,sub4,sub5,mark_total,avg_mark)
Create a BEFORE INSERT trigger to calculate total mark and average mark and update the
corresponding columns.
18. create table phonebook(pname,mobno)

Create a Trigger to insert the old records from the table phonebook to del_phonebook (pname, mobno,
modfy_date) whenever a record is deleted or updated in the phonebook table.

You might also like