Assignment Dbms
Assignment Dbms
SEC: C
SUBMITTED ON : 20 / 9 / 2024
TABLE OF CONTENTS
Lab Task 01................................................................................................................... 3
IMDB-sample Database:........................................................................................3
1. List the first and last names of all the female actors:..................................3
EXECUTION OF QUERY :...........................................................................3
RESULT OF EXECUTION:...........................................................................4
2. List movie names along with their director names of all the movies with a
rank greater than 8.5......................................................................................4
EXECUTION OF QUERY :...........................................................................4
RESULT OF QUERY EXECUTION :..............................................................5
3. List titles of all the movies that are released after 2000, have a rank
greater than 8, and that belong to Action genre............................................5
EXECUTION OF QUERY :...........................................................................6
RESULT OF QUERY EXECUTION :..............................................................6
4. List the first and last names of all the actors who played a role in the
movie Reservoir Dogs, and the roles they played in it....................................7
EXECUTION OF QUERY :...........................................................................8
RESULT OF QUERY EXECUTION :..............................................................8
5. List the first and last names of all the actors who acted in movies directed
by Quentin Tarantino but not in movies directed by Stanley Kubrick.............8
EXECUTION OF QUERY :...........................................................................9
RESULT OF QUERY EXECUTION :..............................................................9
Lab Task 02................................................................................................................. 10
University Database.............................................................................................10
1. Retrieve the title of the course that is pre-req of 'Database System
Concepts'...................................................................................................... 10
EXECUTION OF QUERY :.........................................................................11
RESULT OF QUERY EXECUTION :............................................................11
2. Retrieve the semester and the year in which ‘Einstein’ taught the course
‘Physical Principles’.......................................................................................12
EXECUTION OF QUERY :.........................................................................13
RESULT OF QUERY EXECUTION :............................................................13
3. Retrieve the ID and the title of all courses taken by ‘Shankar’ in ‘Fall 2009’
......................................................................................................................14
EXECUTION OF QUERY :.........................................................................15
RESULT OF QUERY EXECUTION :............................................................15
4. List the name of students who did not take any course in ‘Fall 2009’......16
EXECUTION OF QUERY :.........................................................................17
5. Find building, room number, and capacity of all classrooms in which
student ‘Tanaka’ took all his classes.............................................................18
EXECUTION OF QUERY :.........................................................................19
RESULT OF QUERY EXECUTION :............................................................19
Acknowledgment of Effort..........................................................................................21
Lab Task 01
Querying Database using Relational Algebra
IMDB-sample Database:
1. List the first and last names of all the female actors:
so lets reach our query to select the first and last names and project them . the
query we will use for it is as follows :
First of all the bracket with select operation will be executed and all the strings
with gender ‘Female’ will be selected from the set of actors .
Secondly after the selection the projection operator (π ) will be used to project
only the first_name and the last_name of the female actors .
s
EXECUTION OF QUERY :
RESULT OF EXECUTION:
As we executed the query and as a result no of 289 rows was selected . The result of
execution can be clearly seen in the screenshot .
2. List movie names along with their director names of all the
movies with a rank greater than 8.5
σ (for selection)
⨝ (for natural join)
π (for projection)
for this query we will select the movie names and the names of their directors where
the movie rank is greater than 8.5. The query will be as follows:
First, the selection operation (σ rank > 8.5) will be executed, that will filter the
movies table to include only those movies where the rank is greater than 8.5.
After filtering the movies, the result is joined with the movies_directors table to
link movies with their directors, and then joined with the directors table to get
the names of the directors.
At last , the projection operation selects and displays only the name of the
movie and the first_name and last_name of the directors.
EXECUTION OF QUERY :
Hence as a result of execution again 0 rows were selected because there was no
movie in the set with a rank higher then 8.5 .
3. List titles of all the movies that are released after 2000, have
a rank greater than 8, and that belong to Action genre
σ (for selection)
⨝ (for natural join)
π (for projection)
so we have to give a query for listing all the movies that are released after 2000 and
have rank higher than 8 which belongs to action genre .
π name (σ year > 2000 ∧ rank > 8 ∧ genre = 'Action' (movies ⨝ movies_genres))
The σ operator will filter the movies that were released after the year 2000,
have a rank greater than 8, and belong to the Action genre. This will be done by
combination of two or more conditions using the AND (∧) operator.
The movies will be joined with the movies_genres table to match each movie
genre .
Finally, the π operator selects and displays only the name of the movies that
were relaesed after year 2000 having rank 8+.
EXECUTION OF QUERY :
The movies that were released after the year 2000, have a rank greater than 8, and
belong to the Action genre. These movies are:
Inglorious Bastards
Kill Bill: Vol. 1
Kill Bill: Vol. 2
The natural join between the movies and movies_genres tables filter the results by
the rank and genre and the projection operation displayed only the movie names
based on given conditions . The result can be seen clearly highlighted with green box
in the picture .
4. List the first and last names of all the actors who played a
role in the movie Reservoir Dogs, and the roles they played in
it.
σ (for selection)
⨝ (for natural join)
π (for projection)
so we will write a query to list last and first names of all the actors that were
included in movie roles Reservoir Dogs and the roles they played in that movie.
First, we will look at the list of movies and pick the movie having name
Reservoir Dogs.
We will check the roles played in this movie by matching the movie_id in the
roles set with the id in the movies table.
Next, we combine the roles movies and actors table in order to check which
actor played which role in Reservoir Dogs.
Finally, we show only the first name, last name, and role of each actor in the
movie
EXECUTION OF QUERY :
As we can see that zero rows were selected as result of the query execution. This
means that no actors or roles were found for Reservoir Dogs in the database.
5. List the first and last names of all the actors who acted in
movies directed by Quentin Tarantino but not in movies
directed by Stanley Kubrick.
σ (for selection)
π (for projection)
- (for set difference
Moving towards the query to list the first and last names of all the actors who acted
in the movies that were directed by quentnn tarantio but not the movies directed
by stanley kubrick .
We start by selecting all the actors who worked in movies directed by Quentin
Tarantino by using the σ symbol
The query will first joins between the actors, roles, movies, movies_directors,
and directors tables
The set difference operator will be used to subtract the list of actors . for
example
EXECUTION OF QUERY :
The execution resulted in 0 rows which means that there was no actor who only
worked with quentin but not with stanley kubrik .
Lab Task 02
University Database:
σ (for selection)
π (for projection)
Join (⨝)
We join the prereq table with the course table using course_id and prereq_id.
The selection operator will select the rows where the course title is 'Database
System Concepts'.
The projection operator execute the prereq_id which shows the title of the
prereq course.
In order to retrive the semester and the year in which einstein taught the course of
physical principles :
σ (for selection)
π (for projection)
Join (⨝)
We will use join between the teaches , instructor, and course tables.This links
the instructor with the courses , and details such as the semester and year.
The selection operator will select rows where the instructor's name is 'Einstein'
and the course title is 'Physical Principles'.
The projection operator shows the semester and year from selected results.
The course "Physical Principles" was taught by Einstein in the Fall of 2009.
3. Retrieve the ID and the title of all courses taken by ‘Shankar’
in ‘Fall 2009’
To retrive the id and the tittle of all the courses taken by shankar in fall 2009
σ for ((Selection)
π for (Projection)
⨝ for (Join)
The selection operator will select the rows from the takes table where the
semester is fall , year is 2009 and the student name is shankar .
After the selection, the student, take, and course tables are joined based on
their ids .
The projection operator will show the course_id and title for the relevant
courses taken by shankar .
The query successfully executed and you can see the result highlighted in the green
box :
To list the name of students who did not not take any course in fall 2009
σ for ((Selection)
π for (Projection)
- for (Difference)
The π operator projects all student names from the student table.
The difference operator will remove the names of students who took courses in
fall 2009 from the total students.
The query successfully executed and you can see the result highlighted in the green
box :
Brandt
Chavez
Sanchez
Snow
Aoi
Tanaka
5. Find building, room number, and capacity of all classrooms in
which student ‘Tanaka’ took all his classes
In order to find the building room number and capacity of all the classrooms in which
student tanka took all his classes
σ for ((Selection)
π for (Projection)
⨝ for (Join)
First of all , we will use selection operator (σ) to select tanakas name and then
we join it with the takes table to get his courses.
Then in secon d step we will link tanaka data with the sected information
using the join operation to connect the results with the section table to find the
details about his classes
At last , we will link the class information with the classroom details using
another join to connect the section data with the classroom table, showing us
the building, capacity and the room num.
The query successfully executed and you can see the result highlighted in the green
circle :
Building: Painter
Room Number: 514
Capacity: 10
Acknowledgment of Effort
Best regards,