Professional Documents
Culture Documents
RELATIONAL MODEL
Chapter 2: Relational Model
Structure of Relational Databases
Fundamental Relational Algebra Operations
Additional Relational Algebra Operations
Extended Relational-Algebra-Operations
Null Values
Modification of the Database
attributes
customer-name
customer name customer
customer-street
street customer-city
customer city
customer
Relation r: A B C D
α α 1 7
α β 5 7
β β 12 3
β β 23 10
α α 1 7
β β 23 10
Relation r: A B C
α 10 1
α 20 1
β 30 1
β 40 2
∏A,C (r) A C A C
α 1 α 1
α 1 = β 1
β 1 β 2
β 2
Relations r, s: A B A B
α 1 α 2
α 2 β 3
β 1
s
r
r ∪ s: A B
α 1
α 2
β 1
β 3
Relations r, s: A B A B
α 1 α 2
α 2 β 3
β 1 s
r
r – s: A B
α 1
β 1
Relations r, s: A B C D E
α 1 α 10 a
β 10 a
β 2
β 20 b
r γ 10 b
s
r x s: A B C D E
α 1 α 10 a
α 1 β 19 a
α 1 β 20 b
α 1 γ 10 b
β 2 α 10 a
β 2 β 10 a
β 2 β 20 b
β 2 γ 10 b
Original Slides: Intro to DB (2008-1)
© Silberschatz, Korth and Sudarshan Copyright © 2006 - 2008 by S.-g. Lee Chap 2 - 23
Cartesian-Product Operation
Notation: r x s
Defined as:
r x s = { t q | t ∈ r and q ∈ s}
σA=C(r x s) A B C D E
α 1 α 10 a
β 2 β 20 a
Original Slides:
β 2 β 20 b
Intro to DB (2008-1)
© Silberschatz, Korth and Sudarshan Copyright © 2006 - 2008 by S.-g. Lee Chap 2 - 25
Rename Operation
Allows us to name, and therefore to refer to, the results of
relational-algebra
relational algebra eexpressions.
pressions
Allows us to refer to a relation by more than one name.
returns the
h result
l off expression E under
d the
h name N, and
d
with the attributes renamed to A1, A2, …., An.
branch (branch-name
(branch name, branch-city
branch city, assets)
customer (customer-name, customer-street, customer-only)
d p it ((customer-name,
depositor t account-number)
t b )
Find the loan number for each loan of an amount greater than
$1200
∏loan-number (σamount>1200 (loan))
∏customer-name
t (borrower) ∪ ∏customer-name
t (depositor)
Find the names of all customers who have a loan and an account
at bank.
Find the names of all customers who have a loan at the Perryridge branch but do not
have an account at anyy branch of the bank.
∏customer-name (σbranch-name = “Perryridge”
(σborrower.loan-number
b l b (borrower
b = loan.loan-number
l l x loan)))
– ∏customer-name(depositor)
Query 1
∏customer-name(σbranch-name = “Perryridge”
(σborrower.loan-number = loan.loan-number(borrower x loan)))
Query 2
∏customer-name(
((σloan.loan-number borrower loan-number(
loan loan-number = borrower.loan-number
( σbranch-name = “Perryridge”(loan) ) x borrower
)
)
∏balance(account) –
∏account.balance
b l (
σaccount.balance < d.balance (account x ρd (account) )
)
Set intersection
Natural join
Division
Assignment
Note: r∩s=r–(r–s)
r s
A B
r∩s
α 2
A B C D B D E
α 1 α a 1 a α
β 2 γ a 3 a β
γ 4 β b 1 a γ
α 1 γ a 2 b δ
δ 2 β b 3 b ∈
r s
r s
A B C D E
α 1 α a α
α 1 α a γ
α 1 γ a α
α 1 γ a γ
δ 2 β b δ
Original Slides: Intro to DB (2008-1)
© Silberschatz, Korth and Sudarshan Copyright © 2006 - 2008 by S.-g. Lee Chap 2 - 38
Properties
∏ A1,…,Ak(r) ∩ ∏ A1,…,Ak(s) = ∏ A1 ,…,Ak (r s)
(r
( s)) t=r ((s t))
If R∩S=∅ then r s = r × s (important)
If R=S
R S then
th r s=r∩s
Theta
Th t Join
J i
à combine selection with Cartesian product
r θs = σθ (r × s)
where θ is a predicate on R×S
∏customer-name(σbranch-name=“Uptown”(depositor account))
à Query 2
∏customer-name, branch-name (depositor
(d p it account)
t)
÷ ρtemp(branch-name) ({(“Downtown”), (“Uptown”)})