0% found this document useful (0 votes)
16 views14 pages

Lab Assignment 2 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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

Lab Assignment 2 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 PDF, TXT or read online on Scribd
You are on page 1/ 14

NAME : MUHAMMAD HASEEB ASIF

REGNO: FA23 - BCS - 056

SEC: C

COURSE: D B M S (CSC 270.)

TITLE: ASSIGNMENT 01

SUBMITTED TO: SIR ALI SULTAN

SUBMITTED ON : 17 / 10 / 2024
TABLE OF CONTENTS
ASSIGNMENT 01 ........................................................................................................................................ 3
GIVEN RELATIONS: .............................................................................................................................3
TASK 1: ............................................................................................................................................... 3
 List the year and title of each book: ...................................................................................3
Query: ........................................................................................................................................ 3
Justification: .......................................................................................................................................4
TASK 2: ............................................................................................................................................... 4
 List all information about students whose major is CS. ..................................................... 4
Query: ........................................................................................................................................ 4
........................................................................................................................................................... 4
Justification: .......................................................................................................................................5
TASK 3: ............................................................................................................................................... 5
 List all books published by McGraw-Hill before 1990. .......................................................5
Query: ............................................................................................................................................... 5
........................................................................................................................................................... 5
Justification: .......................................................................................................................................6
TASK 4: ............................................................................................................................................... 6
 List all students with the books they can borrow. ............................................................. 6
Query: ............................................................................................................................................... 6
Justification: .......................................................................................................................................7
TASK 5: ............................................................................................................................................... 7
 Rename AuthorName in AUTHORS relation to Name. ...................................................... 7
Query: ............................................................................................................................................... 7
Justification: .......................................................................................................................................8
TASK 6: ............................................................................................................................................... 8
 List the names of all students who have borrowed a book ............................................... 8
and who are CS majors. .............................................................................................................8
Query: ............................................................................................................................................... 8
Justification: .......................................................................................................................................9
TASK 7: ............................................................................................................................................... 9
 List each book with its keywords ........................................................................................9
Query: ............................................................................................................................................... 9
Justification: .....................................................................................................................................10
TASK 8: ............................................................................................................................................. 10
 List the title of books written by the author ‘Elmasri’. .................................................... 10
Query: ............................................................................................................................................. 10
Justification: .....................................................................................................................................11
TASK 9: ............................................................................................................................................. 11
 List the authors of the books the student ‘Sultan’ has borrowed. .................................. 11
Query: ............................................................................................................................................. 11
Justification: .....................................................................................................................................12
TASK 10: ...........................................................................................................................................12
 Rename AuthorName in AUTHORS relation to Name. .................................................... 12
Query: ............................................................................................................................................. 12
Justification: .....................................................................................................................................13
ASSIGNMENT 01

GIVEN RELATIONS:

 BOOKS (BookId, Title, Publisher, Year)

 STUDENTS (StdId, StdName, Major)

 AUTHORS (AuthorName, Contact)

 BORROWS (BookId, StdId, Date)

 HAS_WRITTEN (BookId, AuthorName)

 DESCRIBES (BookId, Keyword)

TASK 1:
 List the year and title of each book:

Query:

π Title,Year(BOOKS)
Justification:

 π (Pi) is used to select only certain columns from the table.

 We are using it here to get just the Title and Year of the
BOOKS.

 The BOOKS table may contain more columns, but we only


want these two columns.

 In other words we can say it as "Show me the Tittle and


year of each book only , without other details.

TASK 2:
 List all information about students whose major is CS.

Query:

σ Major= ′ComputerScience′ (STUDENTS)


Justification:

 σ (Sigma) is used to filter rows in a table based on the


condition.

 We will filter the STUDENTS table to only select the students


whose major is 'Computer Science'.

 It will return all the details ( ID, name, and major e.t.c) but
only for the student that have major “CS”

 In other words we can say it as "show me only those


students and their details who are stdying "

TASK 3:
 List all books published by McGraw-Hill before 1990.

Query:

σPublisher=′McGraw−Hill′∧Year<1990​ (BOOKS)
Justification:

 · σ (Sigma) will filter rows based on given conditions:

 The publisher is “McGraw-Hill”


 The year of publication is before 1990.

 This query will return all books that meet both conditions.

 We use the ∧ (And) symbol to apply both conditions


together.

 In simple terms, we can say "Show me books published by


McGraw-Hill that were released before the year 1990."

TASK 4:
 List all students with the books they can borrow.

Query:

 STUDENTS ⋈ BORROWS

 πStdName,BookId​ (STUDENTS ⋈ BORROWS)


Justification:

 ⨝ is used to join two tables based on matching values.

 We join the STUDENTS and BORROWS tables using the


StdId attribute to show which students have borrowed
which books.

 This query returns both the StdName and the BookId of books
they have borrowed.

 In simpler terms it is like saying "show me each student


along with the books they have borrowed."

TASK 5:
 Rename AuthorName in AUTHORS relation to Name.

Query:

ρ Name ← AuthorName (AUTHORS)


Justification:

 ρ (Rho) is used to rename an attribute in a relation.

 We use → (arrow) to show which column is being renamed


and what it is being renamed to.

 In this case, AuthorName is being renamed to Name in the


AUTHORS table.

 In simpler terms,we will say "change the AuthorName


column in the AUTHORS table to just Name to make it
simple"

TASK 6:
 List the names of all students who have borrowed a book
and who are CS majors.

Query:

π StdName (σ Major= ′CS′​ (STUDENTS) ⋈ BORROWS)


Justification:

 ⨝ is used to join two tables based on matching values.

 We join the STUDENTS and BORROWS tables using the


StdId attribute to show which students have borrowed
which books.

 This query returns both the StdName and the BookId of books
they have borrowed.

 In simpler terms it is like saying "show me each student


along with the books they have borrowed."

TASK 7:
 List each book with its keywords.

Query:

π Title,Keyword​ (BOOKS ⋈ DESCRIBES)


Justification:

 ⨝ is used to join the BOOKS and DESCRIBES tables.

 This connects each book with its keywords based on the


common BookId.

 π (Pi) is used to select specific columns: Title and Keyword.

 This ensures that only the titles of the books and their
keywords are displayed, while other details will be excluded.

 The result shows each book along with the keywords that
describe it.

TASK 8:
 List the title of books written by the author ‘Elmasri’.

Query:

π Title ( σ AuthorName= ′Elmasri′ (AUTHORS ⋈ HAS_WRITTEN ⋈ BOOKS))


Justification:

 ⨝ is used to join the AUTHORS, HAS_WRITTEN, and


BOOKS tables.

 This connects Authors with the books they have written by linking
AuthorName and BookId.

 σ (Sigma) is used to filter the results for the Author named


'Elmasri'.

 This ensures that we only look at the records related to the author
'Elmasri'.

 π (Pi) is used to select the Title column.

 This means we only want to see the Titles of the books written by
'Elmasri', without other details

 The result shows the Titles of books that have 'Elmasri' as


the AUTHORS.

TASK 9:
 List the authors of the books the student ‘Sultan’ has borrowed.

Query:

πAuthorName​ (σ StdId= ‘Sultan’​ (STUDENTS ⋈ BORROWS) ⋈ HAS_WRITTEN)


Justification:

 ⨝ joins the STUDENTS and BORROWS tables.

 This connects students with the books they borrowed.

 σ (Sigma) filters for the student 'Sultan'.

 This focuses only on records related to 'Sultan'.

 ⨝ joins the result with the HAS_WRITTEN table.

 This links the borrowed books to their AUTHORS.

 π (Pi) selects the AuthorName column.

 This shows only the names of the AUTHORS of the books


borrowed by 'Sultan'.

 The final result lists the AUTHORS for the books that 'Sultan'
has borrowed.

TASK 10:
 Rename AuthorName in AUTHORS relation to Name.

Query:

π BookId​ (σ Keyword = ′database′​ (DESCRIBES)


σ Keyword = ′programming′​ (DESCRIBES))
Justification:

 σ (Sigma) is used to filter the DESCRIBES table for the


keyword 'database'.

 This finds all records of books that have the keyword 'database'.

 σ (Sigma) is used again to filter the DESCRIBES table for the


keyword 'programming'.

 This finds all records of books that have the keyword


'programming'.

 ⨝ joins the two filtered results.

 This connects the books that have the KEYWORD 'database' with
those that have the keyword 'programming'.

 π (Pi) selects the BookId column.

 This means we only want to see the IDs of the books that have
both keywords.

 The final result lists the IDs of books that have both the
KEYWORDS 'database' and 'programming'.

You might also like