Relational Model
Relational Model
● R = (A 1, A 2, …, A n ) is a relation schema
Example:
Customer_schema = (customer_name, customer_street,
customer_city)
attributes
(or columns)
customer_nam customer_stre
customer_city
e et
α α 1 7
α β 5 7
β β 12 3
β β 23 10
α α 1 7
β β 23 10
● Example of selection:
σ branch_name=“Perryridge” (account)
α 10 1
α 20 1
β 30 1
β 40 2
∏A,C (r) A C A C
α 1 α 1
α 1 = β 1
β 1 β 2
β 2
α 1 α 2
α 2 β 3
β 1
s
r
A B
● r ∪ s: α 1
α 2
β 1
β 3
● Defined as:
r ∪ s = {t | t ∈ r or t ∈ s}
● For r ∪ s to be valid.
α 1 α 2
α 2 β 3
β 1
s
r
● r – s:
A B
α 1
β 1
● Defined as:
r – s = {t | t ∈ r and t ∉ s}
● Defined as:
r x s = {t q | t ∈ r and q ∈ s}
● Assume that attributes of r(R) and s(S) are disjoint. (That is, R ∩ S =∅ ).
● If attributes of r(R) and s(S) are not disjoint, then renaming must be
used.
A B C D E
α 1 α 10 a
β 2 β 10 a
β 2 β 20 b
ρ x (E)
returns the result of expression E under the name X, and with the
attributes renamed to A 1 , A2 , …., An .
customer (customer_name,
customer_street, customer_city)
account (account_number,
branch_name, balance)
depositor (customer_name,
account_number)
borrower (customer_name,
loan_number)
● Find the loan number for each loan of an amount greater than
$1200
∏ customer_name ( σbranch_name=“Perryridge”
(σborrower.loan_number = loan.loan_number (borrower x loan)))
∏ customer_name (depositor)
● E1 ∪ E2
● E1 – E2
● E1 x E2
α α 7
α β 7
β β 3
β β 10
sum(c
● g sum(c ) (r)
)
27
account_numb
branch_name balance
er
Perryridge A-102 400
Perryridge A-201 900
Brighton A-217 750
Brighton A-215 750
Redwood A-222 700
branch_name sum(balance)
Perryridge 1300
Brighton 1500
Redwood 700
● Each Fi is either
● the I th attribute of r, if the I th attribute is not updated, or,
● if the attribute is to be updated F i is an expression, involving only
constants and the attributes of r, which gives the new value for the
attribute