0% found this document useful (0 votes)
36 views5 pages

R22 Lab Exercise

Uploaded by

221fa04682
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)
36 views5 pages

R22 Lab Exercise

Uploaded by

221fa04682
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/ 5

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

(20CS201) DATABASE MANAGEMENT SYSTEMS


MODULE -1 BASED
LABORATORY EXERCISES

EXERCISE -1: ER- Diagram WEEK -1


“ In the Boat Club database, club members can make reservations to rent boats for trips lasting
several hours. The database maintains essential details for sailors, including their IDs, names, ratings,
and age. It also stores information about the boats, such as IDs, names, and colors. Each reservation
entry records the boat rented by the sailor, the rental duration in hours, and the specific reservation
date”.
Considering this scenario, how would you design an Entity-Relationship (ER) diagram to
represent the Boat Club database, ensuring efficient boat reservations and seamless management of
sailor information?
EXERCISE-2: WEEK -2
a) Mapping ER-Diagram to Relational Model
Select the ER diagram from the previous exercise that best represents the "Boat Club" database. In
this exercise, students will convert the chosen ER diagram into a relational data model. The relational
model should accurately represent entities, attributes, and relationships in a tabular format. Students
must map the entities from the ER diagram to appropriate tables, including their respective attributes.
Additionally, they should define primary keys and any required relationships to ensure efficient data
management.
b) Constructing Tables using DDL Commands
Continuing from the previous exercises, where students designed an Entity-Relationship (ER)
diagram for the "Boat Club" database and converted it into a relational data model, in this exercise
students will create the actual tables using Data Definition Language (DDL) commands.
In this exercise, students must construct the necessary tables for the "Boat Club" database
using DDL commands. Based on the relational data model, create individual tables for each entity
identified in the ER diagram. Define the attributes for each table, including data types and constraints
such as primary keys and foreign keys where required.
a. While creating the Database make sure to use Primary keys, when required for all the tables.
b. Maintain the Integrity of the data by applying foreign keys.
c. Use Data Constraints like -NOT NULL, CHECK, and UNIQUE whenever required while
constructing the tables.
EXERCISE-3: WEEK - 3
a) Insert Data into Boat Club Database Tables

Figure 2: Boats

Figure 1: Sailors

Figure 3: Reservation

b) Given the database you created, write the SQL queries that answer the following
questions.
LEVEL -1: WEEK- 3, 4
(Select, update, alter, drop, and truncate operations on the single table)
1. Show all the records of Sailors, Boats, and Reservation
2. Find the names and ages of all sailors.
3. Find all sailors with a rating above 8.
4. Display all the names & colors of the boats.
5. Find all the boats with red color.
6. Alter the sailor’s table with column income and insert the values for all the SIDs.
7. Update boat color from blue to Indigo
8. Delete the income column from the sailor’s table.
9. Find the name of the sailors (distinct).
10. Display the schema of sailors and reservations.
11. Initiate a new database to maintain the details of 10 newly recruited sailors for their
job roles:
1. Modify the sailor’s tables SID column data type from varchar to int.
2. Rename the sailor’s table with new_ sailors.
3. Apply the truncate operation on the "new_sailors" table and record your
observations.
4. Perform the drop operation on the new sailors' database and document your
observations.
5. Analyze and outline the distinctions between the drop and truncate operations
based on your observations.
EXERCISE: 4:
LEVEL -2: (Two Tables) WEEK -4

i. Part -1 (Basic retrieval operation using two tables)


1. Find the names of sailors who have reserved boat number 123.
2. Find the names of sailors ' who have reserved red boats.
3. Find the colors of boats reserved by AMY.
4. Find the name of sailors who reserved the boat on 11/10/07.
5. How many boats are reserved by Dustin?
6. Find names of the sailors who have reserved at least one boat.
7. Find the names of sailors who have reserved a red or a green boat.
8. Find all SIDs of sailors who have a rating of 10 or reserved boat number 1.
9. Find the names of sailors who have reserved both a red and a green boat.
10. Find the SID of all sailors who have reserved red boats but not green boats.

ii. Part-2 (String Operations) WEEK- 4,5


1. Find the ids and names of sailors who have reserved two different boats on the same
day.
2. Find the ages of sailors whose name begins with “B”.
3. Find the ages of sailors whose name ends with "y”.
4. Find the ages of sailors whose names begin and end with “b”.
5. Find the ages of sailors whose name has only three letters.
6. Concat bid & bname of Boats & display along with color.
7. Display all sailor’s by removing characters of the boat name if starts with ‗I.
8. Display all Boat information by removing characters of color if ends with ‗d‘
9. Display all Sailor’s information by showing their names in Upper case.
10. Display all boat information by showing their names in Capitalizing the first char.
11. Display Sailor’s information by replacing ‗A‘ with ‗I‘ from SNAME, if any.
EXERCISE: 5

iii. Part-3 (Aggregation Functions) WEEK- 6-7


1. How many reservations are in the "Reservation" table?
2. How many sailors are named "Horatio"?
3. What is the average age of a sailor?
4. List reservations sorted by duration.
5. How many sailors are between 25 and 35 years old and have a rating of 3 or higher?
6. How many times has the boat named Clipper been reserved?
7. List all reservations involving red boats and sailors who are over 30 years old.
8. List the average age of sailors by rating level.
9. Find the names of sailors who are older than the oldest sailor with a rating of 10.
10. Find the sum of the ratings of Sailors.

iv. Part-4: (Group by, having, order by, views)


1. Display all the sailors according to their ages.
2. Display all the sailors according to their ratings (topper first).
3. Displays all the sailors according to rating, if the rating is the same then sort according
to age.
4. To display names of sailors according to alphabetical order
5. Displays all the sailors according to rating (Topper First), if rating is the same then
sort according to age (Younger First).
6. Find the age of the youngest sailor for each rating level.
7. Find the age of the youngest sailor with age >= 18 for each rating with at least 2 such
sailors.
8. For each red boat, find the number of reservations for this boat.
9. Find the average age of sailors for each rating level that has at least two sailors.
10. Find those ratings for which the average age of sailors is the minimum overall rating.
11. Create a view -Expert Sailors with a condition whose rating is >8.
Now perform the following queries on the Expert Sailors
a. Find the Sailors with age > 25 and rating equal to 10.
b. Find the number of Sailors at each rating level (8, 9, 10).
c. Find the age of Oldest as well as Youngest Expert Sailor.
d. Drop the view.

EXERCISE: 6 Week - 8
Construct a company database to perform the given queries.
1. List all employees in the order they were hired to the company.
2. Calculate the sum of all the salaries of managers.
3. List the employee numbers, names and hiredates of all employees who were hired in 1982.
4. Count the number of different jobs in the EMP table without listing them.
5. Find the average commission, counting only those employees who receive a commission.
6. Find the average commission, counting employees who do not receive a commission as if
they received a commission of 0.
7. Find in which city the Operations department is located.
8. What is the salary paid to the lowest-paid employee?
9. Find the total annual pay for Ward.
10. List all employees with no manager.
11. List all employees who are not managers.
12. How many characters are in the longest department name?

Find the requirements below for the construction of the Company Database.

The EMP table


The EMP table stores records about company employees. This table defines and contains the values
for the attributes EMPNO, ENAME, JOB, MGR, HIRE-DATE, SAL, COMM and DEPTNO.
a. EMPNO is a unique employee number; it is the primary key of the employee table.
b. ENAME stores the employee’s name.
c. The JOB attribute stores the name of the job the employee does.
d. The MGR attribute contains the employee number of the employee who manages that
employee. If the employee has no manager, then the MGR column for that employee is left
set to null.
e. The HIREDATE column stores the date on which the employee joined the company.
f. The SAL column contains the details of employee salaries.
g. The COMM attribute stores values of commission paid to employees. Not all employees
receive a commission, in which case the COMM field is set to null.
h. The DEPTNO column stores the department number of the department in which each
employee is based. This data item acts a foreign key, linking the employee details stored in
the EMP table with the details of departments in which employees work, which are stored in
the DEPT table.

The DEPT table


The DEPT table stores records about the different departments that employees work in. This table
defines and contains the values for the attributes as follows:
a. DEPTNO: The primary key containing the department numbers used to identify each
department.
b. DNAME: The name of each department.
c. LOC: The location where each department is based.

The data contained in the EMP and DEPT tables.


The data in the EMP table contains the following 14 rows:

The DEPT table contains the following four rows:

Reference : https://www.cs.uct.ac.za/mit_notes/database/pdfs/chp03.pdf

You might also like