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

ilovepdf_merged (1)

The document outlines the mid-term exam for the Database Management Systems course, detailing various tasks related to database design and SQL queries. It includes scenarios for creating ER diagrams, relational algebra queries, and SQL queries for different database schemas. The exam emphasizes understanding of database concepts, schema design, and the ability to manipulate and query data effectively.
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)
38 views

ilovepdf_merged (1)

The document outlines the mid-term exam for the Database Management Systems course, detailing various tasks related to database design and SQL queries. It includes scenarios for creating ER diagrams, relational algebra queries, and SQL queries for different database schemas. The exam emphasizes understanding of database concepts, schema design, and the ability to manipulate and query data effectively.
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/ 34

Mid-term Exam: : Trimester: Fall 2024

Course Code: CSE 3521, Course Title: Database Management Systems


Total Marks: 30 Duration: 1 Hour 30 Minutes

Any examinee found adopting unfair means will be expelled from the trimester / program as
per UIU disciplinary rules.
_________________________________________________________________________________

1. a) “Urao” is a leading airline in Bangladesh, which has decided to automate its entire 8+
flight management system to enhance service quality and customer satisfaction. To 2=
design the system the following requirement specifications were provided to a 10
software development company:

The airline operates from several airports throughout Bangladesh and internationally.
Each airport has a unique airport code, airport name, city, country, and contact phone
number. The airline operates multiple flights daily. Information stored about each
flight includes the flight number, airline name, departure time, arrival time, flight
status (Scheduled, On-Time, Delayed, or Canceled), and the airports from which the
flight departs and arrives. Each flight has a unique flight number across the airline's
network.

Each flight is assigned a specific aircraft. The details stored for each aircraft include a
unique aircraft ID, model name, manufacturer, number of economy seats and the
number of business class seats. An aircraft can be assigned to multiple flights over
time, but only one flight at a time.

Passengers must register with the airline before booking a flight. Information stored
about passengers includes their first and last names, address, contact number, and
email. Each registered passenger is assigned a unique passenger ID.

Flight bookings are mandatory for passengers intending to travel. A booking includes
the booking ID, booking date, payment status (Paid or Unpaid), total fare, passenger
ID, and the flight number for which the booking is made. Each booking is assigned a
unique booking ID.

Additionally, each flight is staffed by a team of crew members, including the pilot, co-
pilot, and cabin crew. The information stored about crew members includes a unique
crew ID, name, role (Pilot, Co-Pilot, Cabin Crew), years of experience, salary, and the
flight number they are assigned to. A flight may have multiple crew members assigned
to it.

Finally, for each flight, multiple tickets are issued. Ticket information includes a
unique ticket ID, seat number, travel class (Economy or Business), booking ID, and
the passenger ID for the person using the ticket. A booking may include multiple
tickets if several passengers are traveling together.

Now, design an ER diagram for the Scenario capturing all the entities, their
cardinalities and relationships.

b) “All super keys are eligible to be primary keys” - support or refute this statement
with proper reasoning and examples.

2. Draw the corresponding schema diagram based on the erd given in Figure 1. 5

3. Consider the following relational database schema: 1+


1+
Patients (patient_id, name, age, gender, address) 2=
Doctors (doctor_id, name, specialization, salary) 4
Appointments (appointment_id, patient_id, doctor_id, date, time_slot)
Medicine (medicine_id, name, category, price)
Medications (prescription_id, medicine_id, dosage)
Prescriptions (prescription_id, appointment_id, remarks)

Answer the following questions using relational algebra:


a) Find the details of male patients who reside in Palashi.
b) List the names of all patients along with the medicines prescribed to them.
c) Find the specializations of doctors who have never treated patients older than
70 years.
4. Consider the following schema. 2+
2+
Employee (employee_id, name, salary) 1+
Showroom (showroom_id, location, opening_date, manager_id) 2+
Customer (customer_id, name, email, phone_number, address) 2+
Order (order_id, order_date, customer_id, showroom_id) 2=
Product (product_id, name, description, unit_price, stock_quantity) 11
OrderDetails (order_id, product_id, quantity, total_price)

Now write sql queries for the below.

a) Write an SQL query to create the Showroom table. location and opening_date
columns must not allow null values.
b) Add a new column „showroom_id‟ to the employee table, which should store
the showroom each employee is assigned to and ensure that it references the
Showroom table. [Consider this change for the following questions]
c) Find the name, description, and stock quantity of products that have a price
greater than 1000 taka.
d) Find the employee names who earn more than their manager.
e) Find the product ID, name and the number of times each product has been
ordered and display the results in descending order.
f) Find all the showrooms that have the top three most number of employees.
Midterm Exam, Trimester: Spring 2024
Course Code: CSE-3521 Course Title: Database Management Systems
Total Marks: 30 Duration: 1 hour 30 minutes

Any examinee found adopting unfair means will be expelled from the trimester / program
as per UIU disciplinary rules.

1. An event organizer Company named “Elite” is currently try to convert their analog file- 7
system to a digital database. They want it to be able to handle the current processes.

For every event, they store the name of the event, start date, end date, venue, description
in their books. They also store detailed information about the venue like address,
capacity etc. They also assign one of their employee as the supervisor for the event. The
supervisor’s contact info and previous arranged events are needed to be accessed the
current customers.

Elite also keeps information about their employees. For each event they also keep track
of the expenses. They stores the services expenses and expense for buys item/materials
separated books. They want to keep this same when converting to data base system.

They also keep track of the guest list and people who attended the event. Elite want a
database that can handle the above functionalities

Now, design an ER diagram for “Elite” the serves their requirements.

2. Explain the difference between a DBMS and an RDBMS


2

3 Write the corresponding schema of the following ER diagram (Diagram 1). 5

Page 1 of 4
Diagram 1

4. Consider the following schema for a bookstore database: 1+2


2+2
Books Table: [BookID (Primary Key), Title, AuthorID (Foreign Key, referencing Authors Table),
Genre, Price]

Authors Table: [AuthorID (Primary Key), FirstName, LastName, Nationality]

Page 2 of 4
Customers Table: [CustomerID (Primary Key), FirstName, LastName, Email, Phone]

Orders Table: [OrderID (Primary Key), CustomerID (Foreign Key, referencing Customers
Table), Date, TotalAmount]

OrderDetails Table: [OrderDetailID (Primary Key), OrderID (Foreign Key, referencing Orders
Table), BookID (Foreign Key, referencing Books Table), Quantity, Subtotal]

Now, write SQL queries for the following:


i. Retrieve the titles of all books along with their corresponding authors' first and last
names.
ii. Find the total amount spent by each customer, whose last name starts with “s”, in the
year 2021. Include the customer's first and last names in the result set.
iii. Calculate the total sales generated from book sales in each genre. Display the genre
names along with the total amount, sorted in descending order of revenue.
iv. Write a query to identify customers who have purchased books from more than one
genre. Include the customer's first and last names in the result set, along with the
number of genres they've purchased books from.

5. Create the following tables: 3+1


+2
Publishers (id, name, country)
Magazines (id, title, publisher_id(fk), frequency, price)
Subscriptions (id, customer_id(fk), magazine_id(fk), start_date, end_date)

i. Create tables/entities mentioned above (with the primary key & foreign keys).
ii. Add an attribute 'website' to the Publishers table.
iii. Remove 'id' from the Publishers table and make 'name' the primary key. Show the necessary
steps needed to be taken sequentially with corresponding SQL queries.

6. Consider the following relational database schema: 3


Passenger (p_id, name, password, location)
Driver (d_id, name, password, v_id)
Vehicles (v_id, d_id, name, status)
Trips (t_id, p_id, date, time, route, cost)

Answer the following questions using relational algebra:

i) Find all the information of trips between 1000 to 5000 tk on 29th February.

Page 3 of 4
ii) Find the names and vehicle id of drivers who had vehicles whose status are “Unfit”.
iii) Find the output for the following:

Π (t_id, date, route) (σ (cost > 3000 ^ route = (Π location(Passenger))) trips)

Note: Date format is YYYY-MM-DD. And for the last question, write a sentence describing
what
the query will return.

Example: All passenger names whose location is Dhaka.

Page 4 of 4
Midterm Exam, Trimester: Spring 2024
Course Code: CSE-3521 Course Title: Database Management Systems
Total Marks: 30 Duration: 1 hour 30 minutes

Any examinee found adopting unfair means will be expelled from the trimester / program
as per UIU disciplinary rules.

1. An event organizer Company named “Elite” is currently try to convert their analog file- 7
system to a digital database. They want it to be able to handle the current processes.

For every event, they store the name of the event, start date, end date, venue, description
in their books. They also store detailed information about the venue like address,
capacity etc. They also assign one of their employee as the supervisor for the event. The
supervisor’s contact info and previous arranged events are needed to be accessed the
current customers.

Elite also keeps information about their employees. For each event they also keep track
of the expenses. They stores the services expenses and expense for buys item/materials
separated books. They want to keep this same when converting to data base system.

They also keep track of the guest list and people who attended the event. Elite want a
database that can handle the above functionalities

Now, design an ER diagram for “Elite” the serves their requirements.

2. Explain the difference between a DBMS and an RDBMS


2

3 Write the corresponding schema of the following ER diagram (Diagram 1). 5

Page 1 of 4
Diagram 1

4. Consider the following schema for a bookstore database: 1+2


2+2
Books Table: [BookID (Primary Key), Title, AuthorID (Foreign Key, referencing Authors Table),
Genre, Price]

Authors Table: [AuthorID (Primary Key), FirstName, LastName, Nationality]

Page 2 of 4
Customers Table: [CustomerID (Primary Key), FirstName, LastName, Email, Phone]

Orders Table: [OrderID (Primary Key), CustomerID (Foreign Key, referencing Customers
Table), Date, TotalAmount]

OrderDetails Table: [OrderDetailID (Primary Key), OrderID (Foreign Key, referencing Orders
Table), BookID (Foreign Key, referencing Books Table), Quantity, Subtotal]

Now, write SQL queries for the following:


i. Retrieve the titles of all books along with their corresponding authors' first and last
names.
ii. Find the total amount spent by each customer, whose last name starts with “s”, in the
year 2021. Include the customer's first and last names in the result set.
iii. Calculate the total sales generated from book sales in each genre. Display the genre
names along with the total amount, sorted in descending order of revenue.
iv. Write a query to identify customers who have purchased books from more than one
genre. Include the customer's first and last names in the result set, along with the
number of genres they've purchased books from.

5. Create the following tables: 3+1


+2
Publishers (id, name, country)
Magazines (id, title, publisher_id(fk), frequency, price)
Subscriptions (id, customer_id(fk), magazine_id(fk), start_date, end_date)

i. Create tables/entities mentioned above (with the primary key & foreign keys).
ii. Add an attribute 'website' to the Publishers table.
iii. Remove 'id' from the Publishers table and make 'name' the primary key. Show the necessary
steps needed to be taken sequentially with corresponding SQL queries.

6. Consider the following relational database schema: 3


Passenger (p_id, name, password, location)
Driver (d_id, name, password, v_id)
Vehicles (v_id, d_id, name, status)
Trips (t_id, p_id, date, time, route, cost)

Answer the following questions using relational algebra:

i) Find all the information of trips between 1000 to 5000 tk on 29th February.

Page 3 of 4
ii) Find the names and vehicle id of drivers who had vehicles whose status are “Unfit”.
iii) Find the output for the following:

Π (t_id, date, route) (σ (cost > 3000 ^ route = (Π location(Passenger))) trips)

Note: Date format is YYYY-MM-DD. And for the last question, write a sentence describing
what
the query will return.

Example: All passenger names whose location is Dhaka.

Page 4 of 4
Midterm Exam, Trimester: Fall 2023
Course Code: CSE-3521 Course Title: Database Management Systems Total
Marks: 30 Duration: 1 hour 45 minutes

Any examinee found adopting unfair means will be expelled from the trimester / program
as per UIU disciplinary rules.
1. a) Suppose you want to design a software system to manage Gym Membership of 7
UIU. You tried to talk with the gym supervisor to find out the detailed information about
gym management. The requirements are given below,
The gym has a registration process for the students, faculties and staff of UIU. Users
should be able to register for an account with their personal information, including name,
ID, contact information, and a unique username and password. Registered users should
be able to log in securely with their credentials. Gym trainers and administrators, should
have additional privileges and access rights.
The system should provide information about different membership plans, including their
features, pricing, and duration (e.g., monthly, annual). No membership plan with the same
type (regular or economic), price and duration are allowed to be set. However the same
plan may have multiple working features in it. Prospective members should be able to
view and compare the available plans before making a decision.
Prospective gym members should be able to enroll in a specific membership plan. The
system should handle the payment process for membership fees, with options for payment
methods (e.g., credit card, cash).
Members should be able to schedule fitness training sessions, one-on-one consultations
with trainers. Staff members should be able to manage and confirm these appointments.
The system should track member attendance, allowing staff to record check-ins and
check-outs. The check in day and time should be unique for a specific member as no
member is allowed to enter twice in the same day. Attendance records can help in
assessing member engagement and plan utilization.

Now, design an ER diagram for the Scenario. 2

b) Explain the parts of the query processor in database system structure. “An
identifying relationship between two entities is known as a strong relationship”, do you
agree with this statement? If yes, justify your answer with proper explanation.

Page 1 of 3
2 a) Write the corresponding schema of the following ER diagram. 5

3. Consider the following schema 1+2


Teams Table: [TeamID (Primary Key), TeamName, Captain, Coach, ICCRank] 2+2
Players Table: [PlayerID (Primary Key), FirstName, LastName, DateOfBirth, Role (e.g., Batter, Bowler,
All-Rounder, Wicketkeeper), TeamID (Foreign Key, referencing Teams Table)]
Matches Table: [MatchID (Primary Key), Date, Venue, Result (e.g., Win, Loss, Tie, No Result), WinningTeam
(Foreign Key, referencing Teams Table), LosingTeam (Foreign Key, referencing Teams Table) ]
Tournaments Table: [ TournamentID (Primary Key), TournamentName, StartDate, EndDate, HostCountry ]
TournamentMatches Table: [ TournamentMatchID (Primary Key), TournamentID (Foreign Key, referencing
Tournaments Table), MatchID (Foreign Key, referencing Matches Table)]
PlayerPerformance Table: [ PerformanceID (Primary Key), MatchID (Foreign Key, referencing Matches Table),
PlayerID (Foreign Key, referencing Players Table), RunsScored, WicketsTaken, Catches, ManOfTheMatch
(Yes/No)]

Now write sql queries for the below


i. Retrieve the names of all cricket teams in the database.
ii. Retrieve the first names and last names of all players who have participated in matches against
"Team England." Include the name of the opposing team in the result set.
iii. Find the total runs scored by each player in a match, along with their names, in which they scored
more than 50 runs. Sort the results in descending order of runs.

Page 2 of 3
iv. By using subquery, find the date, venue, and result of matches in which players from
"Team Australia" took more than 5 wickets. For each match, list the player's name who
achieved this and the number of wickets they took.
2+2+2

b) Create the following tables.


Customers (id, name, email, phone number)
Products (id, name, price, category)
Orders (id, cust_id(fk), cart_id, date, total_amount)
Carts (id, product_id(fk), quantity)
i. Create tables/entitys mentioned above. (with the primary key & foreign keys )
ii. Add an attribute ‘address’ to the Customers table.
iii. Remove ‘id’ from Customers table make ‘email’ the primary key. Show the
necessary steps need to be taken sequentially with corresponding sql query.
4. Consider the following relational database schema 3

Suppliers (sid : integer, sname : string, address : string , area : string)


Parts (pid : integer, pname : string, color : string)
Catalog (sid : integer, pid : integer, cost : real(number), amount : integer )

Answer the following questions using relational algebra


i. Get the details about all “Parts” available in “Dhaka” area.
ii. Find the “Suppliers” (sid) who is selling “Green” coloured “Wool” and have
more than 500 unit stock.
iii. Find the output for the following:
Π (amount, cost) (σ ( pid = (Π pid (σ (color = ‘red’)parts) ) Catalog)

[Just write a sentence what will the query find.


Example : All supplier with that sells red parts ]

Page 3 of 3
Midterm Exam, Trimester: Summer 2023
Course Code: CSE-3521 Course Title: Database Management Systems
Total Marks: 30 Duration: 1 hour 45 minutes

Any examinee found adopting unfair means will be expelled from the trimester / program
as per UIU disciplinary rules.

1. a) A well-known car rental company in Bangladesh named "SHEBA- Rent A Car" has 7
made the decision to automate the entirety of their manual system in order to better
serve their clients. The data specifications they gave to a software company are as
follows:
The Car Rental Company has several branches throughout Bangladesh. The information
stored for each branch includes the branch's phone number, address, which consists of
the road number, area, city, and zip code. Each branch is assigned a branch number,
which is distinctive across the entire organization. There are several employees assigned
to each branch, including a manager. The manager is in charge of overseeing the
day-to-day operations of a specific branch. The information kept on a staff person
includes their name, title, date of hire, pay, and experience. Within the organization,
every employee has a distinct staff ID. Many rental cars are available at each branch.
The brand name, model number, license plate number, category, daily rental cost, status,
and the driver's name are among the information stored about a car. In a branch, there
may be several cars of the same model. Cars are divided into categories as Private,
Noah, Ambulance, Mini bus, etc. The status shows whether or not a car is available for
rental. A customer must register with the company before renting a car. The first and last
names, address, registration date, and branch name are the data that is stored on a
customer. A unique customer id is provided to each customer. Customers who register
can rent cars. The data stored on each rented car includes the rental number, the renter's
name and phone number, the license plate number, and the date and time of the rental.
The rental number is unique within the company.

Now, design an ER diagram for the Scenario.

b) Explain what you understand by the redundancy control property of the database 2
management system for multiple use. Differentiate between candidate key and primary
key.

Page 1 of 2
2 a) Write the corresponding schema of the following ER diagram 5

b) Mention different kinds of mapping cardinalities and how they can be handled in 3
schema? Explain Identifying Relationship Set and Non-Identifying Relationship Set.

3. a) Consider the following schema 2*5


Employees: [employee_id (primary key), name, age, department_id] =10
Departments: [department_id (primary key), name, location]
Projects: [project_id (primary key), name, start_date, end_date]
Assignments: [assignment_id (primary key), employee_id, project_id]
Customers: [customer_id (primary key), name, address, phone]
Orders: [order_id (primary key), customer_id, project_id, order_date]

Now write sql queries for the below


i. Change the primary key of the orders table and declare order_id, customer_id
and project_id together as a primary key.
ii. Find out the project names where the duration of the project is not more than a
year.
iii. Find out the Employee names of those employees who aged less than the
average age of all employees for each department.
iv. Find out the name and address of each customer who has placed a project order
and the project name is not starting with any vowel or not ending with “ea”.

Page 2 of 2
v. Find out the Employee name and assignment id of the 2nd first employee based
on the number of assignments provided for that employee.

4. Consider the following relational database schema 3


user( user_id, name,email, passward, gender)
post( post_id, user_id(FK), content, likes)
comment(ID, post_id(FK), user_id(FK), time, content)
friend(ID, status)

Answer the following questions using relational algebra


i. Find the post contents along with the user ID which post does not have any
comment.
ii. Get the details about all female users who have an ID in between 2 to 15.
iii. Find the details of all users who have at least one friend and have more than 5
posts.

Page 3 of 2
Midterm Exam, Trimester: Spring 2023
Course Code: CSE-3521 Course Title: Database Management Systems
Total Marks: 30 Duration: 1 hour 45 minutes

Any examinee found adopting unfair means will be expelled from the trimester / program
as per UIU disciplinary rules.
1. a) UIU CSE Alumni Association is planning to launch a web portal for job seekers of 7
UIU and recruiters all over the globe. The job portal manages each job seeker’s profile
where each person is represented by their user id, name, unique email, address, date of
birth, educational qualifications, and job experiences. Educational qualification will
contain degree name, institution name, achieved year, and grade. Job experience will
have job title, institution name, job type, starting date, and duration.

Job seeker’s can be hired by individual recruiters or by the companies. The recruiters
also have their own profiles which will have recruiter id, name, email, and reputation
score.

The recruiters and companies can post job openings to the job portal. The job portal
keeps track of each post’s date, time, contents, and number of viewers. The system also
keeps track of which job seeker is interested in which job posts. One recruiter/company
can recruit more than one job seekers for a job.

Each of the companies are maintained by their unique id, name, address and contact
no. Each user can provide his or her anonymous review of companies. Each of the
reviews contains review id, date, time, review details.

Design an ER Diagram for the scenario that satisfies all the given requirements.
b) Write the corresponding schema of the following ER diagram 4

1
c) Answer the following questions 4
i. What is mapping cardinality?
ii. What are the possible mapping cardinalities for a binary relationship set?
iii. What are the problems with many-to-many relationships?
iv. How do you resolve a many-to-many relationship in the database?
2. a) Consider the following schema 6
Player (id, name, position, ranking, team_id, age)
Team (id, name, ranking, trophy_count)
Coach (id, name, nationality, year_of_experience, trophy_count, ranking, t_id)
Match (id, home_team, away_team, h_score, a_score, day, month, year, result, POTM)
Match_details (p_id, m_id, rating, goal, assist, key_pass, tackle_won, saves)

Now write sql queries for the below


i. Find player name and team name for all the players above 25.
ii. Find the player name who has won the maximum number of POTM awards.
iii. Find the name and average rating of players of the top 5 teams in respect of
trophy count.
iv. Find coach name and total goals scored in the last 10 home matches of his
team. Your result set only includes the coaches whose name is at least 5
characters long and finishes with ‘dan’
b) Consider the following relational database schema 4
passenger ( pid, pname, pgender, pcity)
agency ( aid, aname, acity)
flight (fid, fdate, time, src, dest)
booking (pid, aid, fid, fdate)

Answer the following questions using relational algebra


i. Get the details about all flights from Dhaka to Cox's Bazar.
ii. Find the passenger names for passengers who have bookings on at least one
flight.
iii. Find the passenger names for those who do not have any bookings in any
flights.
iv. Find the details of all male passengers who are associated with ShareTrip
agency.
c) Write sql script to create the database in question 2b. You must fulfill all the 3
constraint requirements. Assume the datatype best suited for each attribute.
d) List two reasons and briefly describe why null values might be introduced into a 2
database.

2
Mid Term Exam, Trimester: Summer 2022
Course Code: CSE-3521, Course Title: Database Management Systems
Total Marks: 30, Duration: 1 hour 45 minutes

Any examinee found adopting unfair means will be expelled from the trimester /
program as per UIU disciplinary rules.

1. a) What do you understand by discriminator? Differentiate between identifying and 2+6


non-identifying relationships.
b) Consider the scenario for Online Art Gallery:

The Art Gallery stores all the artist information including unique artist_id, name, age, and
address. An artist can have multiple addresses containing holding no., street name, and
city. An artist can have many arts.

Art is described by unique art_id, title. Every art has art details. This detail contains
category, style, subject, medium, material, and tag. This system also stores the date when
the art was created.

Curators take care of the arts and place them in the right places(rooms). Art can be taken
care of by many curators and a curator can take care of many arts. Curators assign a
virtual room for each art. A room has a unique room_id, title, and size. The system also
stores the date when a curator places art in a room. Curators have unique curator_id,
name, and hiring date.

Art lovers can see the arts and they have a unique id, name, and address.

Design an ER diagram for the scenario.

2. a) Give a brief explanation about data abstraction in the case of database management 4+7
systems. Can all candidate keys be a primary key? Justify your answer with proper
explanation.
b) Write the corresponding schema of the ER diagram given below.
3. 8+3

Figure 1: HR Schema
a) Use the given HR schema (Figure 1) to write the following queries (I-V)
I. Show the employee id, email and full name of those employees whose employee id
ranges between 110 and 200. Full name format: first_name<space>last_name
II. Write a query to display the top 5 jobs details considering Max_Salary. (Hint:
Higher Max_Salary means better job).
III. Write a query to get the department id-wise difference between the average
salary and minimum salary of the employees. Only consider the departments
having minimum salary of less than 4000.
IV. Write a query to display the city and number of departments in each of the cities
by the descending order of the cities.
V. Write a query to find the name (first_name, last_name), and salary of the
employees who earn more than the average salary and have the string ‘er’ starting
at the 3rd position of their first name. (use subquery)

b) Consider the following relations for question (I) and (II):

I. Write relational algebra for the following query:


Show Student_Id, Student_Name and Course_Name for the students whose
Student_Id is greater or equal to 550 and consider the courses of ‘CSE’
department only.
II. Show the output relation:
∏Student_Id, Course_Id, Department(σCourse_ID>1151(Course Students))
United International University (UIU)
Dept. of Computer Science & Engineering (CSE)

Mid Term Exam, Trimester: Spring 2022


Course Code: CSE-3521, Course Title: Database Management Systems
Total Marks: 30, Duration: 1 hour 45 minutes

Any examinee found adopting unfair means will be expelled from the trimester / program
as per UIU disciplinary rules.

1. a) Compare and contrast different types of attributes used in Entity Relationship Diagram. 3+7
b) You have been asked to design an Employee Tracking Database for CITS UIU. CITS wants
to track information about employees, the employees job history, and their certifications.
Employee information includes employee id, first name, last name, NID, address, city, state,
zip, home phone and email address. An employee will have two addresses, current and
permanent. Job history would include job title, job description, pay grade, salary, joining
date, and total service year. For certifications, they want certification name, type,
complexity level, and date achieved. An employee can have multiple designation at the
same time, (i.e., Professor, Director).
Now draw an ER diagram for this application. Be sure to mark the multiplicity of each
relationship of the diagram. Decide key attributes and identify them on the diagram. Please
state clearly if you make any assumption in your answer.
2. a) “All candidate keys are super keys, but not all super keys are candidate keys” – justify this 3+7
statement with example.
b) Write the corresponding schema of the ER diagram shown in Fig. 1 on the next page.
3. a) Consider the schema in Fig. 2 for writing the SQL mentioned in i to vi: 6+4
i. Write the DDL commands for the existing tables of the given schema:

● Add a new column in the ‘Project’ table named ‘Project_details’ with varchar
(500) data type. Then, change the data type of ‘Project_details’ to varchar
(1000).
● In the ‘Department’ table add two new constraints to the column
Dept_name so that it should be unique and not null.

ii. Show the Dept_Id wise total no of employees and average salary from the
‘Employee’ table. Only consider those departments that have the total no of
employees greater than 5.

iii. From the ‘Department’ table, show Dept_name and Location group name.
Group the location based on the following criteria:

Location Location_group

Tokyo, Singapore, Beijing Asia

London, Paris, Venice Europe

Any other city Unknown

Page 1 of 3
iv. From the ‘Project’ table, show the project details of the projects that have
the pattern “IT” in Project_name with minimum 6 characters in the name. Consider
the projects whose Project_Id is an even number.

v. Use join operation:

Show employee full name, salary, and project name by the descending order of
salary from ‘Employee’ and ‘Project’ table for all the employees (even if they have
not been assigned in any project).

vi. Use subquery:

Show the first_name, salary, Dept_Id of the employees from the ‘Employee’ table.
Include the employees with the maximum salary of 50000 and the minimum
salary of 15000.

b) Consider the following relations,

Shop_details

Shop_ID Name Address

84620 A Uttora

45632 B Gulshan

86145 C Dhanmondi

Inventory

Item_Number Item_Name Available Demand Shop_ID

1 Burger 10 8 45632

2 Pizza 5 15 84620

3 sandwich 6 10 45632

Write relational algebra to,


i. Find out the product names which have available product quantity in between 5 to
8.
ii. Find out those shop names with addresses who have a demand greater than 8 or
less than 3.
iii. Find out the output relation for,
A) π Address, Item_Number (σ Shop_ID > 50000 (Inventory ⋈ Shop_details))
B) π Name, Available, Item_number( σ Available>5(Shop_details X Inventory)

Page 2 of 3
Fig. 1: ER Diagram for Question 2(b)

Fig. 2: Schema Diagram for Question 3(a)

Page 3 of 3
Answer ALL of the following questions:

1. Draw the corresponding Relational Schema for the following ER-Diagram. [CO1] 4

2. Consider the following scenario: 8


A university is organized into different departments. Each department has a unique department
name. The university also stores the opening date, floor no and the phone numbers of the
department. Many students get admitted to a department and faculties work for a department.

Students get a unique student id and their name, date of birth and age is also stored. The name
consists of the first name and the last name of a student. A student pays his/her fees and the fee
date is stored. Students can select one student to be their batch leader.

Courses have their unique course name and the credit hours, number of sections and the type of
the course are stored. Students can enroll in several courses and the trimester name is stored for
each enrollment.

For each fee, it gets a fee number and the amount gets stored. The fee number can not uniquely
identify each fee but can be uniquely identified for each student. [CO1]
3. 8
Table name Column names

Student id (PK), name, dept_name (FK), course_id (FK), total_credit

Department dept_name (PK), building, budget

Instructor id (PK), name, dept_name (FK), salary

Course course_id (PK), title, dept_name (FK), credits

Section section_id (PK), course_id (FK), semester, building, room_no,


time
Write the sql queries for the following questions using the given
a. Find the names of all departments.
b. Find the names of all instructors in the History department.
c. Find all courses taught either in Fall 2020 or in Spring 2021 Semester, or both.
d. Find the names of all students who have taken at least one Computer Science course.
4. a. Briefly describe different types of keys in DBMS. 2
b. Briefly explain mapping cardinalities in DBMS. 2

5. Consider the following collection of relation schemes: 6

professor(profname, deptname)
department(deptname, building)
committee(profname,commname)
a. Find all the professors who are in any one of the committees that Professor Smith is in.
b. Find all the professors who are in at least all those committees that Professor Smith is
in.
c. Find all the professors who are in exactly (i.e., no more and no less) all those
committees that Professor Smith is in.
United International University
Department of Computer Science and Engineering
CSE 3521 – Database Management Systems, Mid Term Exam, Summer 2021
Total Marks: 20, Time: 1 hour

Answer all the questions

1. Convert the following ER Diagram to equivalent relational schema diagram: [4]

2. Consider the following ER Diagram for a Cricket Academy:

Now solve the following query problems using MySQL: [1.5+1.5+3+4]

a) Show all those test match details that were played by the team named ‘teamUIU’ and played between the year
2015 to 2021 inclusive.
b) For each player of allrounder role, show his name and calculate the total number of wickets he has taken.
“Any examinee found adopting unfair means will be expelled from the trimester / program as per UIU disciplinary rules.”
c) For each player, count the total number of his senior teammates of the same role. Do not consider players having
less than 3 senior teammates.
d) Show the player(s) details who was dismissed the maximum number of times by ‘LBW’. If multiple players have the
same maximum number of LBW records then show all of their information.
or,
Show the player(s) details who has scored maximum average runs. If multiple players have the same maximum
average runs then show all of their information.

3. Consider the following database tables:

users orders payments


id name id amount o_date user_id payment_id txn_id date time amount
1 user1 1 1500 2021-01-25 1 1567 0199 2021-01-25 11:30:25 1000
2 user2 2 2000 2021-01-10 2 2345 2345 2021-01-10 04:55:20 2000
3 user3 3 2500 2021-01-18 1 NULL 1567 2021-01-25 18:30:10 1500
4 1000 2021-01-25 3 0199

Show the output of the following MySQL queries: [1.5+2+2.5]

a)
SELECT o_date, amount, user_id, payment_id
FROM orders
WHERE payment_id IS NOT NULL
ORDER BY o_date DESC, amount DESC

b)

SELECT u.name,
order_count.num_orders

FROM users AS u

JOIN
(
SELECT user_id AS u_id, COUNT(*) AS num_orders
FROM orders
GROUP BY user_id
) AS order_count

ON u.id=order_count.u_id

c)

SELECT u.name
FROM users AS u
WHERE 1 < (
SELECT COUNT(*)
FROM orders AS o
WHERE o.user_id = u.id
)

“Any examinee found adopting unfair means will be expelled from the trimester / program as per UIU disciplinary rules.”
United International University
Department of Computer Science and Engineering
CSI 221 Database Management Systems Mid Examination: Fall 2020
Total Marks: 20 Time: 1 hour

Answer all the questions. Numbers to the right of the questions denote their marks.

1. (a) Show the output for the following MySQL query from the emp table: [4]
emp

p q r s
10 4 10 b
SELECT p%q, SUM(r), COUNT(s) 5 2 20 e
FROM emp 16 8 10 a
WHERE s NOT IN(‘a’,‘d’) GROUP BY 27 4 10 f
p%q HAVING COUNT(s)<2; 2 5 30 b
43 10 30 d
61 4 40 f
80 20 20 e
(b) Write necessary MySQL statements for the following query problem based on the given schema: [4]
Student (sid, fname, lname, cgpa, dob, dept)
Show the student id, full name, age for only those students whose department is either “EEE”/“CSE” and
whose birth year is greater than or equal to January 2002 and lname starts and ends with a vowel. Show the
output in ascending order of student’s lname and descending order of their age. [For convenience, you can use
YEAR, DATEDIFF, CONCAT functions]

2. Consider the following relations: [3.5×2]


x y z

A B C D C D E B E
S-101 Sazzad Hossain 3000 Hossain 3000 101 Sazzad 101
S-102 Ayan Mahmud 5000 Hassan 3300 103 Ayan 105
S-103 Sadman Zarif 4000 Zarif 4000 102 Sadman 102
S-104 Sanzida Zahan 2500 Ahmed 2800 104 Nahar 109
Simulate all the following Relational Algebraic Expression. You have to show each and every steps of the simulations.
(a) σ E>102 ((x ./ y)∪(x ./ z))
(b) Show that, x ./ y = x ./ y ∪ x ./ y
3. Based on the following relations s1 and s2, answer the multiple choice questions: [2.5+2.5]
s1
s2
F G H
G K
1 a α
a 100
2 b β
b 200
3 c γ
e 400
4 d β

(a) How many rows will be returned based on this relational algebraic expression: ((s1 ./ s2)∩(s1 ./ s2))
i) 4 ii) 2 iii) 6 iv) 5
(b) Which one of the following is a part of the output of this expression: ((s1 ./ s2)-(s1 ./ s2))
i) (1, a, α, 100) ii) (3, c, γ, 400) iii) (null, e, null, 400) iv) (2, b, β, 200)
United International University
Department of Computer Science and Engineering
CSI 221 - Database Management Systems, Mid Exam, Summer-2020
Total Marks: 20, Time: 1 hour

Answer all the questions

1. Convert the following ER Diagram to equivalent relational schema: [4]

2. Consider the following database tables with sample data:

employees departments
id(PK) name join_date dept_id(FK) man_id(FK) dept_id(PK) name
1 Stanly 2020-06-10 1 2 1 IT
2 Anderson 2020-06-01 2 4 2 Admin
3 Alexandar 2020-06-05 1 6
4 Bill 2020-06-20 2 4
5 Elon 2020-06-18 1 5
6 Zakarburg 2020-06-22 1 5
Here,
- The dept_id column of employees table refers to the dept_id column of departments table.
- The man_id column of employees table refers to the id column of employees table. (man_id = manager id)

Now show the output for each of the following MySQL queries: [1.5*4=6]

i. SELECT id, name, join_date FROM employees WHERE id != man_id ORDER BY join_date DESC LIMIT 0,3;

ii. SELECT e1.name, e2.name FROM employees AS e1 JOIN employees AS e2 ON e1.man_id = e2.id and
e1.join_date > e2.join_date;

iii. SELECT d.dept_id, d.name, COUNT(e.id) AS ‘no of employees’ FROM employees AS e JOIN departments AS d ON
e.dept_id = d.dept_id WHERE e.name LIKE ‘%a%’ GROUP BY d.dept_id, d.name HAVING COUNT(e.id) > 1;

iv. SELECT e1.id, e1.name, e1.dept_id FROM employees AS e1 WHERE e1.join_date = (SELECT MIN(e2.join_date)
FROM employees AS e2 WHERE e2.dept_id = e1.dept_id);

“Any examinee found adopting unfair means will be expelled from the trimester / program as per UIU disciplinary rules.”
3. Consider the following Database Schema:

Song (id:INT, title:VARCHAR(20), singer:VARCHAR(20), album: VARCHAR(20), release_date:DATE, category:


VARCHAR(15), duration:INT, rating:INT)
User (id:INT, name: VARCHAR(20), dob:DATE, email: VARCHAR(30), rank:INT)
Playlist (song_id:INT(FK), user_id:INT(FK), datetime:DATETIME)

a. Write necessary MySQL statements for any 1 of the following query problems: [2]
i. Show the title, album and category of those songs having duration more than 5 minutes, released during the
year 2019 and the category is either ‘Jazz’ or, ‘Rock’ or, ‘Classic’.
ii. Show the top rated 5 song details of singer ‘Topu’.

b. Write necessary MySQL statements for any 1 of the following query problems: [2.5]
i. Show the total no of songs released and their average time duration for each year and each category. Don’t
consider songs from album ‘Folklore’ and also avoid those groups having less than 5 songs.
ii. For each user, show the user name and count the total no of songs that have been added to his playlist
during the year 2020.

c. Write necessary MySQL statements for any 1 of the following query problems: [2.5]
(You can’t use LIMIT statement)
i. Show those songs title and singer name that have the highest rating in its own category.
ii. Show the maximum total number of users from all user ranks.

d. Write necessary MySQL statements for any 1 of the following query problems: [3]
(You can’t use LIMIT statement)
i. Show that song details that is added by maximum number of users in their playlist.
ii. For each rank, show the user name and email who has added maximum number of songs in his playlist.

“Any examinee found adopting unfair means will be expelled from the trimester / program as per UIU disciplinary rules.”
United International University
Department of Computer Science and Engineering
CSI 221 Database Management Systems Mid : Spring 2020
Total Marks: 30 Time: 1 hour 45 minutes

Answer all the questions. Numbers to the right of the questions denote their marks.

1. (a) Consider a university database for the scheduling of classrooms for nal exams. This database could be
modeled as the single entity set exam, with attributes course-name, section-number, room-number, and time.
Alternatively, one or more additional entity sets could be dened, along with relationship sets to replace some
of the attributes of the exam entity set, as
• course with attributes name, department, and c-number
• section with attributes s-number and enrollment, and dependent as a weak entity set on course
• room with attributes r-number, capacity, and building
i. Show an E-R diagram illustrating the use of all three additional entity sets listed. [5]
ii. Explain what application characteristics would inuence a decision to include or not to include each of
the additional entity sets. [2]
(b) Draw a specialization/generalization hierarchy of the following entity to store information in a database. [3]
• A police force help people to stop crimes
I would expect at least TEN entity types. You could consider various entities including dierent types of crime,
dierent types of people, and dierent types of weapon. Make sure that the hierarchy is at least three levels
of entity types deep. Don't show attributes or include relationships other than the sub/supertype entities.
2. Show the results of each query for the given tables: [3+3]

player club
p_id salary club_id rank club_id country_name coach_id budget
(a) 2 20000 5 1 1 Bangladesh 2 30000
3 6000 3 3 5 Brazil 3 20000
1 15000 6 2 10 France 6 20000
5 9000 5 3 6 Brazil 10 50000

SELECT M.club_id, SELECT *


MAX(N.salary) AS max_sal FROM Club AS c1
FROM Club M WHERE 2 = (
JOIN SELECT COUNT(DISTINCT budget)
Player N ON FROM Club AS c2
M.club_id=N.club_id WHERE c2.budget>c1.budget
WHERE N.salary>11000 );
GROUP BY M.club_id
ORDER BY max_sal;

(b) Consider the following Relational Database Schema: [2×3]


relations attributes
no: integer, from: string, to: string, distance: integer,
ights
departs: time, arrives: time, fare: integer
aircraft aid: integer, aname: string, cruisingrange: integer
certied eid: integer, aid: integer
employees eid: integer, ename: string, salary: integer

Note that the Employees relation describes pilots and other kinds of employees as well; every pilot is certied
for some aircraft, and only pilots are certied to y.
i. Find the names of pilots whose salary is less than the price of the cheapest route from Los Angeles to
Honolulu
ii. For all aircraft with cruisingrange over 1000 miles, nd the name of the aircraft and the average salary
of all pilots certied for this aircraft.
iii. Print the enames of pilots who can operate planes with cruisingrange greater than 3000 miles but are not
certied on any Boeing aircraft.
rel-a rel-b rel-b
P Q R S R S T R S T
3. 100 Akbar Ali 20000 Ali 20000 101 Ali 20000 101
103 Tom Cruise 10000 Hanks 42000 103 Hanks 42000 103
104 Tamim Iqbal 50000 Reves 40000 105 Reves 40000 105
102 Tom Hanks 40000 Cruise 10000 101 Cruise 10000 101

You might also like