SQL EXAM Question
SQL EXAM Question
Q1. Write SQL command for a) to f) and write the output of g) on the basis of table MOV.
a) Find the total value of the movie cassettes available in the library.
b) Display a list of all movies with price over 20 and sorted by price
c) Display all the movies sorted by QTY in decreasing order.
d) Display a report listing a movie number, current value and replacement value for each movie in
the above table. Calculate the replacement value for all movies as QTY * Price * 1.15
e) Count the number of movies where Rating is not “G”
f) Insert a new movie in the MOV where Price > 30.
g) Give the output of the following SQL statement
i. SELECT MAX(price) FROM MOV WHERE PRICE > 30
ii. SELECT SUM ( price * qty) FROM MOV WHERE QTY < 4
iii. SELECT COUNT ( DISTINT TYPE)
Q2 (.JANUARY 2006)
7. a) Consider the insurance database given below:
person (driver-id, name, address)
car (license, model, year)
accident (report-number, date, location)
owns (driver-id, license)
participated (driver-id, car, report-number, damage-amount)
1
SQL EXAM QUESTION
9. a) A schema describing theatres, cities where they are located and shows is defined as
follows-
CITY (Name, State, Country)
THEATRE (Name, City, State, Capacity)
SHOW (Title, Artist, Hall, Attendance)
Write the following queries in both 1) SQL and 2) Relational Algebra
i)Find names of artists who performed before at least 5000 people, together with
cities where those performances took place.
ii) Find all states in India where Mr. X has performed.
iii) List all artists who never played in Delhi.
iv) Find the name of theatres in Bombay whose capacity exceeds 5000.
Consider the following tables which give details of customers, trucks and packets booked by
customers, which are carried by trucks and write SQL commands to do the following:
Tables:
CUSTOMER(c_no, c_name, c_address)
TRUCK(t_no, driver_name)
PACKET(p_no, c_no, t_no, date_of_booking, weight, destination)
Queries:
i) Destinations which have received more than 10 packets.
ii) Name of Customers who have sent at least one packet of weight more than one kg to
‘BOMBAY’.
iii) Name of all Customers whose packets were delivered a driver whose name is ‘RAJA’.
iv) Three top customers (names) in terms of total packet weight sent by them. (list is to
be in descending order of total weight.)
v) Name of all Customers whose individual shipments are less than one kg.
b) How cursors addresses the impedance mismatch between host languages and SQL.
c) In what way dynamic SQL is different from embedded SQL?
2
SQL EXAM QUESTION
a) What restrictions apply to the use of aggregate functions within the select?
b) Describe how the process of view resolution works and what restrictions are necessary to
ensure that a view is updatable?
c) Consider the following Relation Schema. An employee can work in more than one department:
Emp (E-id, E_name, Salary)
Dept (d_id, d_name, manager_id, floor_number)
Write the following queries in SQL:
i) Print the name of all employees, who work on the 10th floor and earn salary less than
Rs.50,000.
ii) Print the names of the departments that employee Santa work in.
iii) Print the names of all managers who manage three or more departments on the same
floor.
iv) Print the names of all employees who work on floors where Jane Donald works.
v) Give every employee who works in the toys dept. at 10% raise in the salary.
a) What is the purpose of ‘VIEW’ operation in SQL? Explain how is it created. List its
advantages.
b) What restrictions apply to the use of aggregate functions within the select?
c) Describe how the process of view resolution works and what restrictions are necessary to
ensure that a view is updatable?
Q10.
b) What is meant by Heuristic Optimization? Discuss the main heuristics that are applied to
query optimization?