Schema Relational Algebra Soln
Schema Relational Algebra Soln
Schema Relational Algebra Soln
takes
student
ID
ID
name
course_id
dept_name
sec_id
semester
tot_cred
year
grad
section
course
course_id
course_id
department
advisor
sec_id
i_id
year building
time_slot
credits
building budget
room_no time_slot_id
time_slot_id
day
start_time
end_time
prereq
instructor
classroom
course_id ID
building
prereq_id
name
room_no
dept_name
capacity
teaches
salary
ID
course_id
sec_id
semester
year
2 Relational Algebra
We use relational algebra to specify queries on a database. This is the formal mathematical nota-
tional. Later we will see how this translates into SQL.
1
erations typically take one or two relations as input and return a relation as
output.
Relational algebra is covered in detail in Chapter 6, but we outline a few of
the operations below.
2.1 and
Lets salary. In this example, we could have performed the operations in either
practice...
order, but that is not the case for all situations, as we shall see.
The universitySometimes,
schema and therelations
result of are at the
a query end ofduplicate
contains this handout.
tuples. For example, if we
select the dept name attribute from the instructor relation, there are several cases
of duplication, including “Comp. Sci.”, which shows up three times. Certain rela-
1. What tional languages
is the result ofadhere
σs id=IDstrictly to the
(student ×mathematical
advisor)? definition of a set and remove
duplicates. Others, in consideration of the relatively large amount of processing
required
2. Explain whattoeach
remove
of theduplicates
following from large result
expressions do: relations, retain duplicates. In
these latter cases, the relations are not truly relations in the pure mathematical
(a) sense
σyear≥2009
of the(takes)
term. o n student
Of course,
(b) σyear≥2009 data
(takes n in
o a database must be changed over time. A relation can be
student)
updated by inserting new tuples, deleting existing tuples, or modifying tuples by
(c) ΠID, name, course id (student o n takes)
(a) Find the names of all employees who live in city ‘Miami’.
(b) Find the names of all employees whose salary is greater than $100,000.
2
(c) Find the names of all employees who live in ‘Miami’ and whose salary is greater than
$100,000.
(d) Find the names of all employees who work for “First Bank Corporation”.
(e) Find the names and cities of residence of all employees who work for “First Bank Cor-
poration”.
(f) Find the names, street address, and cities of residence of all employees who work for
“First Bank Corporation” and earn more than $10,000.
3
branch(branch name, branch city, assets)
customer(customer name, customer street, customer city) ** names may not be
unique**
loan(loan number, branch name, amount) ** assume that loan numbers are across all
branches
borrower(customer name, loan number)
account(account number, branch name, balance)
depositor(customer name, account number)
Foreign Keys:
loan and account have foreign key branch name for branch.
(d) Find the names of all borrowers who have a loan in branch ’Down-town’.
(e) Find all loan numbers with a loan value greater than $10, 000.
(f) Find the names of all depositors who have an account with a value greater than $6000.
3
48
University Relations
Chapter 2 Introduction to the Relational Model
Relations and their schemas:
classroom(building, room number, capacity)
department(dept name, building, budget)
course(course id, title, dept name, credits)
instructor(ID, name, dept name, salary)
section(course id, sec id, semester, year, building, room number, time slot id)
teaches(ID, course id, sec id, semester, year)
student(ID, name, dept name, tot cred)
takes(ID, course id, sec id, semester, year, grade)
advisor(s ID, i ID)
time slot(time slot id, day, start time, end time)
prereq(course id, prereq id)