ASSIGNMENT NO 01 DB
ASSIGNMENT NO 01 DB
ASSIGNMENT NO 01
Submitted to:
DR. MADIHA
Submitted by:
MOHSIN IDREES
SP21-BAI-014
Q1) Consider the following relations and answer the questions given below
a) Identify the attributes and explain the integrity constraints which are
applicable on them for the given relations. (apply this on each relation
individually)
Attributes:
Integrity constrains:
Attributes:
o StId: must be unique for each student and not null.
o StName: the name of the student, must not be null.
o Major: the major of the student, must not be null.
o Age: the age of the student, not be null and must be valid.
Integrity constrains:
Attributes:
Integrity constrains:
Attributes:
Integrity constrains:
Attributes:
o DocId: the identifier of the book written by the author, must not be null.
o AName: the name of the author who wrote the book, must not be null.
Integrity constrains:
DESCRIBES (Keyword):
Attributes:
Integrity constrains:
DESCRIBES (Keyword):
o Keyword: string
c) After completing part b determine which relations are union compatible and
which are not. (Specify the reasons)
Q2) Apply relational algebra concepts on the relational schema given below
to solve the given queries. [6]
Find only the flight time and ids for passenger with flights to Karachi before
06/11/2020.
Explanation:
Find the passenger names, gender for passengers who have bookings on at least
one flight.
Explanation:
Find the passenger names for those who do not have any bookings in any flights to
Lahore and Karachi.
Explanation:
Get the details of flights that are scheduled on both dates 01/12/2020 and
02/12/2020 between 16:00 to 18:00 hours.
σ(fdate = '01/12/2020' ∧ time >= '16:00' ∧ time <= '18:00', flight) ⋂ σ(fdate =
'02/12/2020' ∧ time >= '16:00' ∧ time <= '18:00', flight)
Explanation:
Find the details of all male passengers who are associated with more than one
agency and rename attribute aname to agency-name.
γ(pid, agency-count)(booking_passenger)
Explanation:
o ρ operator is used to rename the joined relation as "booking_passenger"
for ease of understanding.
o π operator is used to select the required attributes from the joined
relation passenger, booking, and agency and rename the attribute
"aname" as "agency-name".
o ⨝ is used to join the passenger, booking, and agency relations on the
common attributes pid and aid.
o γ is used to group the joined relation by the passenger id and count the
number of distinct agencies associated with each passenger.
o σ is used to select the male passengers who are associated with more
than one agency and rename the "aname" attribute to "agency-name".
Count the number of agencies that are located in the same city as passenger with id
245 and display the output as total count, city name and passenger name and id.
Explanation:
o ρ operator is used to create two relations for passenger with id 245 and
agency table named "passenger245" and "agency", respectively.
o π operator is used to project the "acity" attribute from the "agency"
relation and count the number of agencies in each city by using the
GROUP BY clause with the attribute "acity". The result is saved in the
relation "agency_city".
o ⨝ is used to join the "passenger245" and "agency_city" relations on the
common attribute "acity".
o π operator is used to project the required attributes including
"count_agency", "acity", "pname", and "pid" from the joined relation
"passenger245 ⨝ agency_city ⨝ passenger".
o The final result includes the count of agencies, city name, passenger
name, and passenger id in which the passenger with id 245 is located and
where at least one agency is also located.