0% found this document useful (0 votes)
58 views35 pages

4-Mid Term Exam-06-07-2023

number(4); salary: number(7,2)) Subject( subject_code: number(3); subject_name: varchar2(20); credits: number(2)) Teaches( tname: varchar2(20); subject_code: number(3); hours: number(2)) Note: ‘sc’ stands for ‘student count’ Do the following 1. Create the above tables with primary keys on appropriate fields. Enforce the foreign keys on fields of ‘Teaches’ table. 2. Ensure that ‘designation’ should be either ‘Professor’ or ‘Assistant Professor’. Also ensure that ‘salary’ should be greater than zero. 3. Add at least

Uploaded by

SARTHAK GOYAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views35 pages

4-Mid Term Exam-06-07-2023

number(4); salary: number(7,2)) Subject( subject_code: number(3); subject_name: varchar2(20); credits: number(2)) Teaches( tname: varchar2(20); subject_code: number(3); hours: number(2)) Note: ‘sc’ stands for ‘student count’ Do the following 1. Create the above tables with primary keys on appropriate fields. Enforce the foreign keys on fields of ‘Teaches’ table. 2. Ensure that ‘designation’ should be either ‘Professor’ or ‘Assistant Professor’. Also ensure that ‘salary’ should be greater than zero. 3. Add at least

Uploaded by

SARTHAK GOYAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

School of Computing Science and Engineering

Database Systems
Mid-Term Exam

Slot: L5+L6
Question 1)
Consider the following relational schemas

Passenger(pname: varchar2(10); pnr_number: number(8); amount: number(5,2); doj: date; status:


varchar2(3))
Reserved_for(pnr_number: number(8); train_no: number(5))
Train(train_no: number(5); train_name: varchar2(10); source: varchar2(15); destination: varchar2(15))

Note: ‘doj’ stands for date of journey.


Status may be ‘cf’(confirmed), ‘ncf’ (not confirmed), and ‘c’(cancelled).

Do the following
1. Create the above tables with composite primary on Passenger table and primary key on Train table.
Enforce the foreign keys on fields of ‘Reserved_for’ table.
2. See that ‘status’ field value should be any one of these ‘cf’ , ’ncf’, and ‘c’. Also see that ‘source’ and
‘destination’ fields should never be empty. Ensure that the date of journey should be not more than 30
days from date of reservation.
3. Add at least 6 records to each table as per the requirements of queries given as below.
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks-

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. List tickets numbers along with train names that travels from ‘Bangalore’ to ‘Chennai’ on journey
dates between 13-November-2015 and 15-November-2015.
5. Display date of journey field values in the format ‘ddth of month yyyy’ by adding one day to it.
6. Get the total number of tickets reserved on each date of journey.
7. List the ticket numbers whose amount is more than the amount of every ticket on 13-November-
2015. (Sub Query)
8. Create a virtual table to display ticket numbers along with train numbers and train names on a
particular date of journey those travel from ‘Bangalore’ to ‘Tirupati’
-----------------------------------------------------End of Question1 --------------------------------------------------------------
Question 2)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. Retrieve the SSN and Last name of employees who were born in May Month.
2. Retrieve the employee details whose salary is less than 25000 and greater
than 10000
3. List the employees with Supervisors.
4. How many male employees have supervisor with number 333445555?
5. Print each department name along with its average, maximum and minimum
salary
6. Find out the number of employees over 40 years of age.
7. List the First name of the employees who has dependents.
8. Find the Manager who gets highest salary among managers.
Question 3)

Consider the following relational schemas

Actor( aname: varchar2(20); role: varchar2(15); sex: char; amount :number(6); city:
varchar2(10))
Performs(aname: varchar2(20); title: varchar2(20))
Skit(title: varchar2(20); theme: varchar2(15); duration: number(3); rating:varchar2(3))

Do the following

1. Create the above tables with primary keys on appropriate fields. Enforce the foreign keys on fields of
‘Performs’ table.
2. Put a check constraint to see that rating of the skit should be any one of these A, A+, and
A++. Also see that the fields ‘role’ and ‘amount’ should be unique and not empty respectively.
Include ‘street’ column in the’Actor’ table of string data type.
3. Add at least 6 records to each table as per the requirements of the queries given below
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks-

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. Change the city to ‘Chennai’ of an actor whose name start with ‘J’ and acted in the skit with
title ends with ‘n’.
5. Display number of male actors acted and their total remuneration skit wise.
6. Retrieve names of actors who perform in more than or equal to 2 skits.
7. List skit names in which female artists acted is more than or equal to male artists acted. (Sub
Query)
8. Create a virtual table that shows skit names with rating A+ and in which actors have been paid an
amount less than or equal to Rs.25000.

----------------------------------------------End of set 3-----------------------------------------------------------------------------


-
Question 4)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. Write a PL/SQL block to print employee name and his manager name
2. Write a PL/SQL program to print factorial of a given number.
3. Determine the minimum salary drawn by employees in each department.
4. Calculate average salary of employees over 40 years of age
5. Display the department name whose projects are not functioning in Houston.
6. List the managers to whom at least one employee is reporting to them.
7. List the departments that do not have any employees.
8. Find the names of employees who work on maximum number of projects.
Question 5)
Consider the following relational schemas

Singer(singerid: number(4); singer_name: varchar2(20); city: varchar2(15); street: varchar2(10);


city: varchar2(15))
Sings(singerid: number(4); lyricid: number(4))
Lyric( lyricid: number(4); duration: number(3); dor: date; lyric_writer: varchar2(20); movie:
varchar2(25))

Note: ‘dor’ stands for ‘date of recording’.

Do the following

1. Create the above tables with primary on appropriate fields. Enforce the foreign keys on the
fields of ‘Sings’ table.
2. Ensure that duration of each lyric should be not less than 5mins and not more than 7 mins.
Also ensure that field ‘singer_name’ should not be null. Eliminate ‘street’ field.
3. Add at least 6 records to each table as per the requirements of queries given below
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks-

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. Display lyricid sung by each singer and then get total number of lyrics sung by each singer.

5. Retrieve maximum, minimum and average duration of songs for each movie.
6. Display date of recording of the song by adding one month to each one of them.
7. Retrieve the lyric whose duration is more than the duration of any other lyric in the movie
‘Khiladi’. (Sub Query)
8. Create a virtual table that displays singer names in capitals, movie title in smaller letters and the
length of movie titles.

---------------------------------------------------End of set 5------------------------------------------------------------------------


-
Question 6)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. List the employees who were born on or before 1980.
2. Display total number of employees and total salary drawn in each
department
3. Find the employee who is getting the minimum salary among all of his
colleagues.
4. List the First Name of employees in department number 5 who gets more
salary when compared to that of employees in department 4.
5. Create a virtual table containing the details of employees working in
department 1and number 3.
6. Display the first name and SSN of employees along with the project names
for employees whose project location is 'salt lake city'.
7. List the total working hours of employees according to their departments.
8. List the details of managers dependents.
Question 7)
Consider the following relational schemas

Tutor( tname: varchar2(20); designation: varchar2(20); school: varchar2(5); place: varchar2(15))


Conducts(tname: varcha2(20); t_name: varchar2(20))
Tutorial(t_name: varcha2(20); duration: number(3); start_date: date; t_fee: number(6,2))

Note: ‘start_date’ stands for start date of tutorial classes, ‘designation’ to be either ‘assistant
professor’, ‘professor’ or ‘senior professor’.

Do the following

1. Create the above tables with primary keys on appropriate fields. Enforce the foreign keys on fields of
‘Conducts’ table.
2. Ensure that fields ‘school’ and ‘t_fee’ should not be empty. Also see that duration of any tutorial
should be not more than 4 hours per session. Eliminate ‘place’ field.
3. Add at least 6 records to each table as per the requirements of queries given as below
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks-

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. Obtain tutorial details conducted by tutors whose designation has got ‘professor’ as a substring.
5. List out the first 3 characters and last 3 characters of tutorial names whose’ duration’ is less than 3
hours.
6. Get the school names whose total number of tutorials conducted is more than or equal to 2.
7. Display tutorial name whose fee is less than the tutorial fee of any other tutorials. (Sub Query)
8. Create a virtual tableto get the tutorial names along with tutor names those conducted by schools
‘scse’ and ‘site’.
---------------------------------------------------------End of set 7------------------------------------------------------------------
Question 8)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. Display Managers whose join date is between January 2011 to December
2011
2. Display the length of address field from employee table
3. List the First Name of employees in department number 5 who gets more
4. salary when compared to that of employees in department 4.
5. Create a virtual table containing the details of employees working in
department 1 and number 3.
6. Create a view to store the first name, SSN of employees and corresponding
7. projectnames.
8. List the total working hours of employees according to their departments.
9. List the details of managers dependents.
10. Display the details of employees who are getting minimum salary in their
project.
Question 9)

Consider the following relational schemas

Emp(eid: char(4); ename: varchar2(20); doj: date; incentive: number(6,2))


Works_On(eid:char(4); pid:char(4))
Proj(pid: char(4); pname: varchar2(15); budget: number(6,2); plocation: char(10))

Note: ‘doj’ stands for date of joining. Sample empid is ‘e001’ and sample pid is ‘p001’.

Do the following

1. Create the above tables with primary keys. Enforce foreign keys on the fields of ‘Works_On’ tab
2. Change the data type of field ‘plocation’ to accommodate variable size values in it, change the name
of the field ‘incentive’ to ‘perk’, and also see that employee id and project id should start with letter ‘e’
and ‘p’ respectively.
3. Insert at least 6 records in each table as per requirements of queries given below
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. Show project names in capitals and their locations as first letter in capital.
5. Display project name and employee name for projects either with budget not less than 3 lakhs or
located at ‘Chennai’
6. Retrieve number of employees works on each project and number of projects each employee works
on.
7. Get the project names whose budgets are the same as the budget of the project located at
‘Hyderabad’. (Sub Query)
8. Create a virtual table that displays locations where more than 2 projects are conducted.

-------------------------------------------------End of set 9--------------------------------------------------------------------------


Question 10)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. How many male employees have supervisor with number 333445555?
2. Print each department name along with its average , maximum and
minimum
3. salary
4. Create a view to store the first name, SSN of employees and corresponding
5. project names.
6. List the First name of the employees who has dependents.
7. Find the Manager who gets highest salary among managers.
8. Display the details of employees who are getting minimum salary in their
9. project.
10. Find the names of employees whose department location is ‘Houston’
11. Find the subordinates of ‘Doug E Gilbert’ to two immediate levels.
Question 11)
Consider the following relational schemas

Customer(cid: number(3); cname: varchar2(20); birthdate: date; address: varchar2(30))


Takes(cid: number; account_no: number(5))
Loan(loan_no: number(5); loan_type: varchar2(10), dol: date; amount: real)

Note: ‘dol’ stands for ‘start date of loan’ by the customer. Sample ‘cid’ are 100,101 and so on. Sampe
Loan no are 10000,10001 and soon. Loan type may be ‘Vehicle loan’, ‘Personal Loan’, ‘Housing Loan’ and
so on.

Do the following

1. Create the above tables with primary key on appropriate fields. Enforce the foreign key on the fields
of ‘Takes’ table.
2. See that customer names should be unique. Ensure that ‘birthdate’ of each customer should be 5
years earlier than current sysdate. Add field ‘branch_name’ to ‘Loan’ table.
3. Add at least 5 records to each table as per the requirements of queries given below
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. Get total number customer name whose loan amount more than Rs.30000.
5. Display loan details of customers whose age is not less than 35 years.
6. Retrieve the minimum, maximum and average loan amount of all loans sanctioned by each branch till
to date.
7. Display loan amounts those are more than every loan amount of loans given by ‘Katpadi’ branch of
the bank. (Sub Query)
8. Create a virtual table to display customer details that have taken loan at ‘Katpadi’ branch.

---------------------------------------------End of set 11 ---------------------------------------------------------------


Question 12)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. Display Managers whose join date is between January 2011 to December
2011
2. Display the length of address field from employee table
3. List the First Name of employees in department number 5 who gets more
4. salary when compared to that of employees in department 4.
5. Create a virtual table containing the details of employees working in
department 1 and number 3.
6. Create a view to store the first name, SSN of employees and corresponding
7. projectnames.
8. List the total working hours of employees according to their departments.
9. List the details of managers dependents.
10. Display the details of employees who are getting minimum salary in their
project.
Question 13)
Consider the following relational schemas

Tourist (tourist_id: number(4); person_name: varchar2(20), dob: date; address: varchar2(20))


Travels_On (tourist_id: number(4); tour_id: char(4))
Tour(tour_id: char(4); tour_name: varcha2(20); tour_type: varchar2(6); agent: varchar2(15);
amount: number(6,2))

Note: tourist_id should be 1000,1001 and so on. tour_id should be t001, t002 and so on.
amount should be 1000.50, 1324.50 and so on

Do the following

1. Create the above tables with primary on appropriate fields. Enforce the foreign key on the
fields of ‘Travels_on’ table.
2. Put a check constraint to see that each tour id should start with letter ‘t’ and tour type be
either 1-day, 1-week or 2- week. Also ensure that ‘dob’ and ‘address’ fields are non empty.
3. Populate each table with at least 5 records as per the requirements of given queries
Mandatory: Display the structure and content of each table for each change and store it in your file to
be uploaded. It carries 5 marks

Answer the following queries in SQL and obtain required output (Output for each query be there in
your file and it carries half of the marks allotted to the query)
4. Show the tour details in ascending order of tour name and descending order of agent.
5. Display least and highest tour package amount offered by each travel agent.
6. List tourist names along with their tour names and package amount, whose age is equal to 25
years.
7. Display tour names whose package amount is less than the package amount of every tour
offered ‘Bharat Agency’ (Sub Query)
8. Create a virtual table to display tourist names who are on tour with id ‘t001’ and having
‘chennai’ as substring in their address.

------------------------------------------------------------End of set13--------------------------------------------------
-
Question 14)

Schema’s

Table Name: Employee

Attribute Data Type


First Name VARCHAR(15)
Mid Name CHAR(2)
Last Name VARCHAR(15)
SSN Number CHAR(9)
Birthday DATE
Address VARCHAR(50)
Sex CHAR(1)
Salary NUMBER (7)
Supervisor SSN CHAR(9)
Department Number NUMBER (5)

Table Name: Department

Attribute Data Type


Department Name Varchar(15)
Department Number Number(5)
ManagerSSN CHAR(9)
ManageStartDate DATE

Table Name: Project

Attribute Data Type


Project Name VARCHAR(15)
Project Number NUMBER(5)
Project Location VARCHAR(15)
Department Number NUMBER(5)
1. Display Managers whose join date is between January 2011 to December
2011
2. Display the length of address field from employee table
3. List the First Name of employees in department number 5 who gets more
4. salary when compared to that of employees in department 4.
5. Create a virtual table containing the details of employees working in
department 1 and number 3.
6. Create a view to store the first name, SSN of employees and corresponding
7. projectnames.
8. List the total working hours of employees according to their departments.
9. List the details of managers dependents.
10. Display the details of employees who are getting minimum salary in their
project.

You might also like