Relational Model
Relational Model
Deposit
Custmomer Branch
Borrow
Predicate may involve: =, ≠, <, ≤, >, ≥ and connectives: and (Λ) and or (˅)
ii. “Find those customers who have the same name as their street”.
Πcname(σcname = street (customer))
“Find the name of all the customers who live in the same city and
same street as Shiva”.
how to express p?
“Find the name of the person who has got the highest balance”.
Additional Operations:
Set Intersection Operation (∩)
“Find all customers with both a loan and an account at the Majestic branch”.
Πcname(σbname = “majestic” (borrow)) ∩
Πcname(σbname = “majestic” (deposit))
r Λ s = r – (r-s)
The natural join operation forms a Cartesian product of its two arguments,
performs a selection forcing equality on those attributes that appear in both
relation schemas and finally removes duplicate columns.
r1(R1) r2(R2)
A1 A2 A2 B
a b b d
c b e f
r1 x r2
A1 R1.A2 R2.A2 B
a b b d
a b c f
c b b d
c b e f
A1 R1r.A
1 2 r2 R2.A2 B
a b b d
c b b d
r s = ΠRUS (σr.A1 = s.A1 ∩ r.A2 = s.A2… ∩ r.An = s.An (r x s))
where R ∩ S = {A1,A2,…An}
“Find all customers who have a loan at the bank and the cities in
which they live”
Πborrow.cname, ccity (σborrow.cname = customer.cname (borrow X customer) )
≡ Πcname,ccity (borrow customer)
“Find the assets and name of all branches which have depositors living
in Calcutta”.
Πasset, bname (σccity = “calcutta” (branch deposit customer) )
“Find all customers who have both an account and a loan at the
university branch”.
Division Operation (÷)
“Find all customers who have an account at all branches located in
Delhi”.
Πbname, cname (deposit) ÷ Πbname (σbcity = “Delhi” (branch ))
Formally, let r(R) and s(S) be relations, and let S ⊆ R. the relation r ÷
s is a relation on schema R-S. A tuple t is in r ÷ s if for every tuple t s ϵ
s, there is a tuple tr in r satisfying both of the following.
tr [S] = ts [S]
tr [R - S] = ts [R - S]
A non-procedural language.
Query format: {t│p(t)}
“Find all customers who have a loan for an amount greater than 5000”.
{t │ ∃ s ϵ borrow (t[cname] = s[cname] Ʌ s[amount] > 5000) }
“Find the branch name, loan number, customer name and amount for
loans of over 5000”.
{<b, l, c, a> │ <b, l, c, a> ϵ borrow Ʌ a > 5000 }
“Find all customers who have a loan for an amount > 5000”.
{<c> │ ∃ b, l, a (<b, l, c, a> ϵ borrow Ʌ a > 5000 ) }
Views:
Any relation that is not part of the conceptual model but is made
visible to a user as a “virtual relation” is called a view.
A view must be recomputed for each query that refers to it.
A view definition causes the saving of an expression to be substituted
into queries using the view.
{t │ ¬ (t ϵ borrow)}