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

Database Management Systems (CSE 220) : Vikas Bajpai

This document discusses relational algebra queries on sample database schemas. It contains 9 questions that express queries in relational algebra on two database schemas: 1) A computer products schema with tables for Computer, Model, and Maker. Queries find makers of laptops, makers of 3 desktop models, phone numbers of desktop makers with speed 3.2, and more. 2) A student course registration schema with tables for Student, Course, and Registered. Queries list registered courses, courses with no registrations, students registered to specific courses, and more. The document provides the relational algebra expression for each query question on the sample schemas. This allows practicing expressing different types of queries in relational algebra

Uploaded by

yash sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Database Management Systems (CSE 220) : Vikas Bajpai

This document discusses relational algebra queries on sample database schemas. It contains 9 questions that express queries in relational algebra on two database schemas: 1) A computer products schema with tables for Computer, Model, and Maker. Queries find makers of laptops, makers of 3 desktop models, phone numbers of desktop makers with speed 3.2, and more. 2) A student course registration schema with tables for Student, Course, and Registered. Queries list registered courses, courses with no registrations, students registered to specific courses, and more. The document provides the relational algebra expression for each query question on the sample schemas. This allows practicing expressing different types of queries in relational algebra

Uploaded by

yash sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Database Management Systems

(CSE 220)
Vikas Bajpai
Relational Algebra

Tutorial
Question 1: Consider the following database
schema computer products:
– Computer (maker, model, category)
– Model (num, speed, ram, hd, price)
– Maker (name, address, phone)
• Where
– maker indicates the manufacturer of the computer
– category takes values such as “desktop”, “laptop”,
“server”;
– Following inclusion dependencies hold
• maker ⊆ name
• model ⊆ num
• Express following queries in relational algebra:
1. Find all the makers who make
some laptop(s)
1. Find all the makers who make
some laptop(s)
πmaker (σcategory= “laptop” (Computer))
2. Find all the makers who make at
lease three different desktop models”
2. Find all the makers who make at
lease three different desktop models”
πmaker(σmodel1≠model2 ∧ model2≠model3 ∧ model3≠model1
(ρmodel1←model (σcategory=“desktop”(Computer))
⋈ ρmodel2←model (σcategory=“desktop”(Computer))
⋈ ρmodel3←model (σcategory=“desktop”(Computer))))
3. Find the phone numbers of all
the makers who make desktops with
speed = 3.2”
3. Find the phone numbers of all
the makers who make desktops with
speed = 3.2”
πmaker σmodel =num (σcategory = “desktop” (Computer) ×
σspeed = 3.2 (Model))
4. “Find the makers who don’t
make any desktop, and do make
some laptop(s)”
4. “Find the makers who don’t
make any desktop, and do make
some laptop(s)”
(Computer − σcategory=“desktop”(Computer))) ∩
πmaker(σcategory=“laptop”(Computer)
5. Find the makers who make all
models with speed faster than 3.2
5. Find the makers who make all
models with speed faster than 3.2
πmaker, model (Computer) / (ρ model←num
πnum(σspeed>3.2(Model))
Question 2: Consider the following relations:
– Student(ssn, name, address, major)
– Course(code, title)
– Registered(ssn, code)
• Express following queries in relational algebra:
1. List the codes of courses in which
at least one student is registered
(registered courses):
1. List the codes of courses in which
at least one student is registered
(registered courses):
πcode ( Registered)
2. List the titles of registered
courses (of those in 1.)
2. List the titles of registered
courses (of those in 1.)
πcode ( Course ⋈ Registered )
3. List the codes of courses for
which no student is registered
3. List the codes of courses for
which no student is registered
πcode ( Course ) - πcode ( Registered )
4. The titles of courses for which
no student is registered.
4. The titles of courses for which
no student is registered.
πname ( (πcode ( Course ) - πcode (
Registered )) ⋈ Course)
5. Names of students and the titles
of courses they registered to.
5. Names of students and the titles
of courses they registered to.
πname,title ( Student ⋈ Registered ⋈ Course)

πname,title ((σ1=4 ∧ 5=6 (Student x Registered x Course))


6. SSNs of students who are
registered for ‘Database Systems’ or
‘Analysis of Algorithms’.
6. SSNs of students who are
registered for ‘Database Systems’ or
‘Analysis of Algorithms’.
πssn ( Student ⋈ Registered ⋈ (σ title=’Database
Systems’ Course)) ∪ πssn ( Student ⋈
Registered ⋈ (σ title=’Analysis of Algorithms’ Course))
7. SSNs of students who are
registered for both ‘Database
Systems’ and ‘Analysis of
Algorithms’.
7. SSNs of students who are
registered for both ‘Database
Systems’ and ‘Analysis of
Algorithms’.
πssn ( Student ⋈ Registered ⋈ (σ title=’Database
Systems’ Course)) ∩ πssn ( Student ⋈ Registered
⋈ (σ title=’Analysis of Algorithms’ Course))
8. List of courses in which all
students are registered.
8. List of courses in which all
students are registered.
πcode, ssn ( Registered ) / πssn ( Student
)
9. List of courses in which all
‘ECMP’ major students are
registered.
9. List of courses in which all
‘ECMP’ major students are
registered.
πcode, ssn ( Registered ) / πssn (σ major=’ECMP’ Student )

You might also like