RDBMS Lab Guide
RDBMS Lab Guide
RDBMS Lab Guide
LAB GUIDE
DATABASE
MANAGEMENT
SYSTEM
DAY 2 ASSIGNMENTS
Assignment 6 ER AND NORMALISATION TECHNIQUES
LAB GUIDE
Assignment 9 ER AND NORMALISATION TECHNIQUES
DAY 3 ASSIGNMENTS
Assignment 12 TABLE CREATION
Assignment 15
DAY 4 ASSIGNMENTS
Assignment 16
Assignment 17
Assignment 18
Assignment 19
DAY 5 ASSIGNMENTS
Assignment 20
Assignment 21
DAY 6 ASSIGNMENTS
3
DAY 1 ASSIGNMENTS
ASSIGNMENT 1 : ER MODELLING TECHNIQUES
LAB GUIDE
LAB GUIDE
LAB GUIDE
LAB GUIDE
is required to take a variety of drugs during different
parts of the day such as morning, afternoon and night.
LAB GUIDE
value.
LAB GUIDE
D. Instructors , including identification number , name ,
department and title
LAB GUIDE
B. Construct an alternative ER Diagram that uses only a
binary relationship between students and course
offerings. Make sure that only one relationship exists
between a particular student and course offering pair,
yet you can represent the marks that a student gets in
different exams of a course offering.
LAB GUIDE
• Course with attribute name , department and c_number
• Section with attributes s_number and enrollment ,
dependent as a weak entity set on course
• Room with attributes r_number , capacity ,and building
LAB GUIDE
LAB GUIDE
LAB GUIDE
EMPLOYEE
Column name Data type Description
LAB GUIDE
HIREDATE Date Date of joining
SAL Number Basic Salary
COMM Number Commission
DEPTNO Number Department Number
DEPARTMENT
Column name Data type Description
LAB GUIDE
7788 Scott Analyst 7566 9/12/82 3000 20
7839 King President 17/11/81 5000 10
7844 Turner Salesman 7698 8/9/81 1500 0 30
7876 Adams Clerk 7788 12/1/83 1100 20
7900 James Clerk 7698 3/12/81 950 30
7902 Ford Analyst 7566 4/12/81 3000 20
7934 Miller Clerk 7782 23/1/82 1300 10
♦ List the names of employees whose employee numbers are 7369, 7521, 7839, 7934,
7788.
LAB GUIDE
♦ List employees not belonging to department 30, 40, or 10.
♦ List employee names for those who have joined between 30 June and
31 Dec. ‘81.
♦ List the names of employees who are not eligible for commission.
♦ List the name and designation of the employee who does not report to anybody.
♦ List names of employees whose names have “i” as the second character.
♦ List name, salary and PF amount of all employees. (PF is calculated as 10% of basic
salary)
♦ List names of employees who are more than 2 years old in the company.
♦ List the employee details in the ascending order of their basic salary.
LAB GUIDE
♦ List the employee name and hire date in the descending order of the hire date.
♦ List employee name, salary, PF, HRA, DA and gross; order the results in the
ascending order of gross. HRA is 50% of the salary and DA is 30% of the salary.
♦ List the department number and total salary payable in each department.
♦ List the jobs and number of employees in each job. The result should be in the
♦ List the total salary, maximum and minimum salary and average salary of the
employees jobwise.
♦ List the total salary, maximum and minimum salary and average salary of the
♦ List the average salary of the employees job wise, for department 20 and display
Suppliers
S# SName Status City
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
LAB GUIDE
Parts
P# PName Color Weight City
P1 Nut Red 12.0 London
P2 Bolt Green 17.0 Paris
P3 Screw Blue 17.0 Rome
P4 Screw Red 14.0 London
P5 Cam Blue 12.0 Paris
P6 Cog Red 19.0 London
Projects
J# Jname City
J1 Montago London
J2 Cat Paris
J3 Box London
J4 Montago Rome
J5 Eagles Athens
Shipment
S# P# J# Qty
S1 P1 J1 350
S1 P3 J3 120
S2 P1 J1 620
S3 P2 J3 700
S2 P2 J4 250
S4 P3 J2 125
S5 P4 J2 325
LAB GUIDE
♦ Get all S#/P#/J# triples such that all are co-located.
♦ Get al S#, P#, J# triples such that they are not all co-located.
♦ Get all pairs of cities such that a supplier in the first city supplies to a Project in the
second city.
♦ Get J# for projects supplied by at least one supplier not in the same city.
♦ Get all pairs of part numbers such that some supplier supplies both the indicated
parts.
♦ For each part supplied to a project, get the P#, J# and corresponding total quantity.
♦ Get J# for projects using at least one part available from supplier S1.
♦ Get supplier numbers for suppliers supplying at least one part supplied by at least
♦ Get supplier numbers for suppliers with a status lower than that of supplier S1.
♦ Get project numbers for projects not supplied with any red part by any London
supplier.
Write the SQL commands to create a database schema for the following relational schema:
LAB GUIDE
101 Richa 1800000 wholesaler
102 Rishi 1000000 retailer
103 Rijesh 4000000 wholesaler
104 Kalyan 4800000 Wholesaler
311 Karthik 5500000 retailer
LAB GUIDE
103 101 10 102 Panama City 12-Dec-03
104 101 20 101 Los Angeles Null
105 102 200 102 Rome Null
106 100 50 101 Sioux City 18-Sep-03
107 104 500 100 Manhattan Null
108 103 50 103 San Francisco Null
109 104 25 101 San Francisco Null
110 102 200 103 London 11-Oct-98
111 103 100 101 London 09-Sep-99
112 104 500 100 London 18-Jun-88
113 104 200 100 London 11-Oct-98
114 104 50 103 Manhattan 29-May-03
115 100 75 103 Los Angeles 17-Sep-02
116 101 55 102 Baltimore 01ul-02
117 103 45 101 Paris Null
118 103 45 100 Rome Null
119 103 45 102 Los Angeles Null
120 104 45 102 London Null
121 100 150 102 Sioux City Null
122 101 500 102 Manhattan Null
123 102 250 102 San Francisco 31-Jul-02
124 311 0.5 102 Denver Null
125 311 100 102 St. Louis Null
TRUCK_# DRIVER_NAME
100 Jensen
101 Sasi
102 Hrithik
103 Jake Stinson
LAB GUIDE
Data for CITY table
CITY_NAME POPULATION
London 100000000
Paris 120000000
Rome 200000000
Panama City 1230000000
San Francisco 20000000
Sioux City 5000000000
Manhattan 10000000
Los Angeles 7000
Baltimore 2000
Denver 1000
St. Louis 5000
♦ What are the names of customers who have sent packages (shipments) to Sioux City?
♦ To what destinations have companies with revenue less than $1 million sent pack-
ages?
♦ What are the names and populations of cities that have received shipments weighing
over 100 pounds?
♦ Who are the customers having over $5 million in annual revenue who have sent ship-
ments weighing less than 1 pound?
♦ Who are the customers having over $5 million in annual revenue who have sent ship-
LAB GUIDE
ments weighing less than 1 pound or have sent a shipment to San Francisco?
♦ Who are the drivers who have delivered shipments for customers with annual reve-
nue over $20 million to cities with populations over 1 million?
♦ List the cities that have received shipments from customers having over $15 million
in annual revenue.
♦ List the names of drivers who have delivered shipments weighing over 100 pounds.
♦ List the name and annual revenue of customers who have sent shipments weighing
over 100 pounds.
♦ List the name and annual revenue of customers whose shipments have been deliv-
ered by truck driver Jensen.
♦ List customers who had shipments delivered by every truck. ( use NOT EXISTS)
♦ List cities that have received shipments from every customer. ( use NOT EXISTS)
♦ List drivers who have delivered shipments to every city. (use NOT EXISTS)
LAB GUIDE
♦ Customers with annual revenue between $1 million and $5 million.
♦ Customers with annual revenue over $5 million.
♦ Use these views to answer the following queries:
♦ Which drivers have taken shipments to Los Angeles for customers with
revenue over $5 million?
♦ What are the populations of cities which have received shipments from
customers with revenue between $1 million and $5 million?
♦ Which drivers have taken shipments to cities for customers with revenue
under $1 million, and what are the populations of those cities?
LAB GUIDE
centralized database system to assist in the more
effective and efficient running of the clinics. The re-
lational schema for the PerfectPets database looks as fol-
lows:
LAB GUIDE
LAB GUIDE
the city “Brea”.
h. List the name (first and last) of every owner who owns “Chihuahua”.
i. List the name of every owner who owns a pet that has visited a clinic located in the
city “Fullerton”.
j. List the name and type of pet for every pet that has been treated more than 2 days
and spent more than $100 for treatment.
k. List the staff’s first name and last name for all staffs who are managers but do not
manage any clinic (e.g., the position is manager).
l. List the name (first and last) pet owner who made an appointment for his/her pet but
did not bring it to any clinic (e.g., no record of examination or treatment).
m. Find the name and type of pet that has received the most expensive treatment.
n. Find the busiest registration month for pet in the past. We assume that the more pets
are registered, the busier the month is.
o. List the name and type for every pet, along with its owner’s last name. If a pet does
not have an owner, display ‘lost pet’ instead.
p. Find the average cost of treatment for each type of pet?
q. List the name (first and last) of every pet owner who owns more than one pet.
r. List the name of every drug and its current stock that need to be re-ordered. A drug
needs to be re-ordered when the quantity in stock is less than the quantity of re-order
level. Sort the result by the quantity in stock.
s. Find the clinic number that has the least amount of drug value (e.g., a drug value is
computed as drug cost * quantity in stock) in its pharmacy stock.
t. List the city (e.g., for pet owners) and the total amount of cost spent for pet
treatment in each city.
u. List the clinic number, phone number, and its city that has all kinds of drugs available
in its stock.
Trainer
TrainerID TraineeName EmailID Phone
1 Abraham [email protected] 9844499999
2 Boyce [email protected] 9844499989
3 Camilla [email protected] 9844499997
4 Davis [email protected] 9844499996
LAB GUIDE
5 Elsa [email protected] 9844499499
6 Ferguson [email protected] 9844409999
7 Abraham [email protected] 9844459999
8 Gordon [email protected] 9844996999
9 Hilton [email protected] 9899677999
10 Boyce [email protected] 9877788999
11 Zenith [email protected] 9869977799
12 Abraham [email protected] null
Course_Details
CourseID CourseName
GPF Programming Fundamentals
GDB Relational Database Management System
ODB Oracle 8i
OVB Visual Basic
JJA Java
JAJ Advanced Java
DNT Introduction to DotNot Technology
DCS Programming in C#
DDB SQL Server 2000
MDB DB2
MCS CICS
Batch_Schedule
LAB GUIDE
Batch2 GDB 21-JAN-2007 31-JAN-2007
Batch2 DNT 1-FEB-2007 10-FEB-2007
Batch2 DCS 2-FEB-2007 15-FEB-2007
Batch2 DDB 16-FEB-2007 22-FEB-2007
Batch3 GDB 25-JAN-2007 02-FEB-2007
Batch3 JJA 3-FEB-2007 20-FEB-2007
Batch3 JAJ 21-FEB-2007 28-FEB-2007
Batch4 GPF 1-FEB-2007 11-FEB-2007
Batch4 GDB 12-FEB-2007 22-FEB-2007
Batch4 MDB 23-FEB-2007 28-FEB-2007
Batch4 MCS 1-MAR-2007 15-MAR-2007
Feedback
LAB GUIDE
1 GPF Batch2 4.28
12 ODB Batch1 4.32
12 OVB Batch1 4.08
12 MDB Batch4 4.12
12 MCS Batch4 4.08
12 JAJ Batch3 4.12
12 DNT Batch2 4.12
12 DDB Batch2 4.12
12 DCS Batch2 4.08
12 JJA Batch3 4.67
2 GDB Batch2 4.61
2 GDB Batch3 4.41
2 GDB Batch4 4.52
♦ List the name of trainers who have handled more than one course
♦ List the trainer id, name of trainers and the number of different courses handled
LAB GUIDE
♦ Get the complete training duration for each batch
♦ Get the course details and trainer details for each batch as on 20 feb 2007.
♦ List the id of trainers who have handled more than one course for a batch along with
the batch name
♦ List the trainers who have handled all the courses for a batch