Database Management Systems (CSE 220) : Vikas Bajpai
Database Management Systems (CSE 220) : Vikas Bajpai
(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)