Professional Documents
Culture Documents
Relation
Relational DBMS products store data about entities in
relations, which are a special type of table
1
Relation
36
Queries
Information is extracted from a
database
by writing queries
query inputs: relations
query result: relation
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
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
5
Ex:
1)Select the EMPLOYEE tuples whose department
number is 4
σdno = 4 (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)
47