You are on page 1of 7

Relational Model Concepts

† Introduced in 1970 by E.F. Codd


„ He was an IBM engineer
„ Based on set theory (relation)
„ The model used mathematics known as “relational algebra”
† Now the standard model for commercial DBMS products
† stores information in :
„ Relation: Table or file
„ Tuple: Row or record
„ Attribute: Column or field
„ Primary keys
„ Data types : Text - Dates & times – Numbers – Objects
„ DB schema = a set of relation specifications

† MS Access, Oracle, SQL Server Sybase , DB2, MySQL, etc. 34

Relation
† Relational DBMS products store data about entities in
relations, which are a special type of table

† A relation is a two-dimensional table that has the following


characteristics:
„ Rows contain data about an entity
„ Columns contain data about attributes of the entity
„ All entries in a column are of the same kind
„ Each column has a unique name
„ Cells of the table hold a single value (atomic)
„ The order of the columns is unimportant
„ The order of the rows is unimportant
„ No two rows may be identical 35

1
Relation

Table that is not relation: Multiple Entries per Cell

36

Queries
† Information is extracted from a
database
by writing queries
„ query inputs: relations
„ query result: relation

† queries are read-only operations

† The SQL command for queries


select
37

2
Relational Algebra
† The basic set of operations for the relational model is known as the
relational algebra. These operations enable a user to specify basic retrieval
requests.

† The result of a retrieval is a new relation, which may have been formed
from one or more relations. The algebra operations thus produce new
relations, which can be further manipulated using operations of the same
algebra.
† The relational algebra defines mathematical operations on relations (Formal
Language)
„ provides a solid theory for dealing with queries
† These operations define the meaning of SQL queries
† Query optimization:
„ SQL queries are translated to expression trees containing algebraic operators
„ expression trees are reorganized to optimize the order of operations
38

Relational Algebra Operations


† set theoretic:
„ union, intersection, difference, cross-product
„ usual mathematical meaning

† relational database unique:


„ select, project: extraction from a single relation
(unary operation)
„ join: combining two relations (binary operation)

39

3
DB State

40

Suppliers – Parts
S
SP

41

4
The Select Operation σ
† SELECT operation is used to select a subset of the tuples
from a relation that satisfy a selection condition. It is a
filter that keeps only those tuples that satisfy a qualifying
condition – those satisfying the condition are selected
while others are discarded.

† Syntax:
σ<selection condition> (R)
† Selection condition may contain
AND, OR, NOT, =, <, ≤, >, ≥, ≠
42

SELECT Operation Properties


† The SELECT operation σ <selection condition>(R) produces a relation
S that has the same schema as R

† The SELECT operation σ is commutative; i.e.,


σ <condition1>(σ < condition2> ( R)) = σ <condition2> (σ < condition1> ( R))

† A cascaded SELECT operation may be applied in any order; i.e.,


σ <condition1>(σ < condition2> (σ <condition3> ( R))
= σ <condition2> (σ < condition3> (σ < condition1> ( R)))

† A cascaded SELECT operation may be replaced by a single


selection with a conjunction of all the conditions; i.e.,
σ <condition1>(σ < condition2> (σ <condition3> ( R)))
43
= σ <condition1> AND < condition2> AND < condition3> ( R)

5
Ex:
1)Select the EMPLOYEE tuples whose department
number is 4
σdno = 4 (EMPLOYEE)

2)Select the EMPLOYEE tuples whose salary is greater than


$30,000
σsalary >30000 (EMPLOYEE)

3) Select the tuples for all employees who either


work in department 4 and make over $25,000
per year, or work in department 5 and make
over $30,000
σ(dno=4 AND salary>25000) OR (dno = 5 AND salary
>30000) (EMPLOYEE)

6
PROJECT Operation π
† It selects certain columns from the table, and creates a
vertical partitioning
„ It removes any duplicate tuples
„ Project is not a commutative

† Syntax:
π<attribute list> (R)
Ex: list each employee’s first and last name and salary
π lname, fname, salary (EMPLOYEE)

π sex, salary (EMPLOYEE)

Duplicate values are eliminated (F, 25000) 46

PROJECT Operation Properties


„ The number of tuples in the result of projection π
<list> (R)is always less or equal to the number of
tuples in R.

„ If the list of attributes includes a key of R, then


the number of tuples is equal to the number of
tuples in R.

47

You might also like