Professional Documents
Culture Documents
Relational Model
• A relational database consists of a collection
of tables,with a unique name.
• A row in a table represents a relationship
among a set of values.
• A row in a table is called a tuple.
• For each attribute,there is a set of permitted
values called as domain
Example of a Relation-account
Basic Structure of Relational Model
• Formally, given sets D1, D2, …. Dn a relation r is a subset of
D1 x D2 x … x Dn
• Example
• customer_name = {Jones, Smith, Curry, Lindsay, …}
• /* Set of all customer names */
– customer_street = {Main, North, Park, …} /* set of all street names*/
– customer_city = {Harrison, Rye, Pittsfield, …} /* set of all city names */
Then r = { (Jones, Main, Harrison),
(Smith, North, Rye),
(Curry, North, Rye),
(Lindsay, Park, Pittsfield) }
is a relation over
customer_name x customer_street x customer_city
Attribute Types
• Each attribute of a relation has a name
• The set of allowed values for each attribute is called
the domain of the attribute
• Attribute values are (normally) required to be atomic;
that is, indivisible
– E.g. the value of an attribute can be an account number,
but cannot be a set of account numbers
• Domain is said to be atomic if all its members are
atomic
• The special value null is a member of every domain
Relation Schema
• The overall design of the relation is termed as Relation
schema.
Example:
Customer_schema = (customer_name,
customer_street, customer_city)
Relation Instance
• The current values (relation instance) of a relation
are specified in a relation instance.
• A tuple, represented by a row in a table attributes
(or columns)
customer_name customer_street customer_city
1 7 1 7
A=B ^ D > 5 (r)
5 7 23 10
12 3
23 10
Example of selection:
branch_name=“Perryridge”(account)
Project operation
• The project operation is a unary operation that returns its argument
relation,by certain attributes left out.
• Uppercase letter is used to denote project operation.
• Notation: A1,A2....An(r)
• where A1, A2 are attribute names and r is a relation name.
r x s: A B C D E
1 10 a
1 10 a
1 20 b
1 10 b
2 10 a
2 10 a
2 20 b
Rename Operation
• used to name, and therefore to refer to, the results of relational-algebra expressions.
• It is denoted by the lowercase Greek letter rho( )
• Example:
x (E)
x(A,A1...An) (E)
returns the result of expression E under the name X, and with the
attributes renamed to A1 , A2 , …., An .
Additional Operations
We define additional operations that do not add
any power to the relational algebra, but that
simplify common queries.
• Set intersection
• Natural join
• Division
• Assignment
Set-Intersection Operation
• It is used to find tuples that are present
commonly in both tables.
• Notation: r s
• Assume:
– r, s have the same arity
– attributes of r and s are compatible
1 1
2 2
3
1 s
1
1
3 r s: A
4
6
1
2
r
• We can find all (customer name,branch
name)pairs for which the customer has an
account by
r1=customer_name, branch_name (depositor ⋈
account)
• We can obtain all branches in Brooklyn by
r2=branch_name (branch_city = “Brooklyn” (branch))
• Find all customers who have an account at all
branches located in Brooklyn city.
• r1 r2=
customer_name, branch_name (depositor ⋈
account)
branch_name (branch_city = “Brooklyn” (branch))
Assignment Operation
• The assignment operation () provides a
convenient way to express complex queries.
– The result to the right of the is assigned
to the relation variable on the left of the .
– May use variable in subsequent expressions.
– Example:
temp1 R-S (r )