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

Assignment Dbms

Uploaded by

haseebasif.edu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Assignment Dbms

Uploaded by

haseebasif.edu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

NAME : MUHAMMAD HASEEB ASIF

REGNO: FA23 - BCS - 056

SEC: C

COURSE: D B M S (CSC 270.)

TITLE: LAB ASSIGNMENT 1

SUBMITTED TO: SIR ALI SULTAN

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:

For this query we will use two operators


 σ (for selection)
 π (for projection)

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_name, last_name (σ gender='F' (actors))

 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 this query, we will use three operators:

 σ (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:

π movies.name, directors.first_name, directors.last_name (σ rank > 8.5 (movies


⨝ movies_directors ⨝ directors))

 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 :

Moving forward to the execution of the query ………………………………….


RESULT OF QUERY EXECUTION :

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 this query, we will use three operators:

 σ (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 :

RESULT OF QUERY EXECUTION :

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 this query, we will use three operators:

 σ (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.

π actors.first_name, actors.last_name, roles.role (σ movies.name = 'Reservoir


Dogs' ∧ roles.movie_id = movies.id (roles ⨝ movies ⨝ actors))

 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 :

RESULT OF QUERY EXECUTION :

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 this query, we will use three main operators:

 σ (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

 People worked with Quentin - people worked with Stanley Kubrick

EXECUTION OF QUERY :

RESULT OF QUERY EXECUTION :

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

Querying Database using Relational Algebra

University Database:

1. Retrieve the title of the course that is pre-req of 'Database


System Concepts'.

In order to retrive the tittle of course which is the pre-req of database :

we will use three main operators:

 σ (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.

π prereq.prereq_id (σ course.title = 'Database System


Concepts' ( prereq ⨝ course ))
EXECUTION OF QUERY :

RESULT OF QUERY EXECUTION :

The prereq for the course 'Database System Concepts' is CS-101.


2. Retrieve the semester and the year in which ‘Einstein’ taught
the course ‘Physical Principles’

In order to retrive the semester and the year in which einstein taught the course of
physical principles :

we will use three main operators:

 σ (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.

π teaches.semester, teaches.year ( σ instructor.name = 'Einstein' ∧


course.title = 'Physical Principles' ((teaches ⨝ instructor ⨝ course)))
EXECUTION OF QUERY :

RESULT OF QUERY EXECUTION :

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

we will use three main operators:

 σ 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 .

π takes.course_id, course.title (σ student.name = 'Shankar' ∧


takes.semester = 'Fall' ∧ takes.year = 2009 (student ⨝ takes ⨝
course))
EXECUTION OF QUERY :

RESULT OF QUERY EXECUTION :

The query successfully executed and you can see the result highlighted in the green
box :

 CS-101: Intro. to Computer Science

 CS-347: Database System Concepts


4. List the name of students who did not take any course in ‘Fall
2009’.

To list the name of students who did not not take any course in fall 2009

we will use three main operators:

 σ for ((Selection)
 π for (Projection)
 - for (Difference)

 The π operator projects all student names from the student table.

 The σ operator selects students from the takes table.

 The difference operator will remove the names of students who took courses in
fall 2009 from the total students.

π student.name (student) - π student.name (σ takes.semester =


'Fall' ∧ takes.year = 2009 (student ⨝ takes))
EXECUTION OF QUERY :

RESULT OF QUERY EXECUTION :

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

we will use three main operators:

 σ 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.

π section.building, section.room_number, classroom.capacity


(((σ student.name = 'Tanaka' (student) ⨝ takes) ⨝ section) ⨝
classroom)
EXECUTION OF QUERY :

RESULT OF QUERY EXECUTION :

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

DEAR SIR ALI SULTAN,

I hope you see the effort I put into this


assignment. I look forward to your feedback
and hope will be recognized and
appreciated.I hope you will check full
assignment because I followed your advice
and justified every thing what where and
why I did so the assignment went little bit
long .If you will wish I will explain everything
also in class . I don’t know what happened
but in someway I received 2 lab tasks and in
motivation I compeleted both tasks .

Thank you for your consideration.

Best regards,

You might also like