2. Relational Algebra in RDBMS
Relational Algebra is a procedural query language that provides
a formal foundation for retrieving and manipulating data stored in
relational databases. It uses operators to perform queries,
combining one or more relations (tables) to produce a new
relation as a result.
3. Fundamental operators used in Relational
Algebra
Selection(σ)
Projection(π)
Union(U)
Set Difference(-)
Set Intersection(∩)
Rename(ρ)
Cartesian Product(X)
13. Relational Calculus in RDBMS
Relational Calculus is a non-procedural query language that specifies
what data to retrieve rather than how to retrieve it. It is based on
predicate logic and focuses on describing the conditions for the desired
result.
There are two main types of relational calculus:
1.Tuple Relational Calculus (TRC)
2.Domain Relational Calculus (DRC)
14. Differences Between Relational
Algebra and Calculus
Aspect Relational Algebra Relational Calculus
Type
Procedural: Specifies steps to retrieve
data.
Declarative: Specifies what data
to retrieve.
Basis Based on algebraic operations. Based on predicate logic.
Ease of Use
Requires knowledge of operations
and execution.
More intuitive and easier for users.
Focus Focuses on how to retrieve data. Focuses on what data to retrieve.
15. Tuple Relational Calculus (TRC)
Definition: Queries are expressed using tuple variables, which represent
rows (tuples) in a relation.
Syntax
t: A tuple variable.
P(t): A predicate that specifies the condition(s) the tuple ttt must satisfy.
Example:
Retrieve names of employees earning more than $50,000:
16. Components of TRC
Tuple Variables: Represent rows in a relation.
Predicates: Conditions involving attributes of tuples, constants, and logical
operators ( , ,¬).
∧ ∨
Quantifiers:
Universal Quantifier ( )
∀ : States that a condition holds for all tuples.
Existential Quantifier ( )
∃ : States that there exists at least one tuple satisfying
the condition.
17. Domain Relational Calculus (DRC)
Definition: Queries are expressed using domain variables, which represent individual
attributes (columns) rather than entire tuples.
Syntax:
Example:
Retrieve names of employees earning more than $50,000:
18. Differences Between TRC and DRC
Aspect Tuple Relational Calculus (TRC) Domain Relational Calculus (DRC)
Variables
Uses tuple variables (representing
rows).
Uses domain variables (representing
columns).
Focus Focuses on tuples (rows). Focuses on attributes (columns).
Syntax ( { t P(t) } )
Complexity Easier for tuple-based conditions. Suitable for attribute-level queries.
19. Codd's rules
Dr. Edgar F. Codd proposed Codd's 12 rules (or 13 including Rule 0) as
a guideline for relational database systems.
These rules are intended to define what constitutes a true relational
database system and ensure its adherence to relational principles.
20. Rule 0: The Foundation Rule
A system qualifies as a relational database management system (RDBMS)
if it fully supports the relational model.
Rule 1: The Information Rule
All data should be stored in tables (relations), and all data is accessible
through table column values.
Rule 2: Guaranteed Access Rule
Each data item (value) in a database must be accessible using a
combination of a table name, primary key, and column name.
Rule 3: Systematic Treatment of Null Values
The database must allow null values to represent missing, unknown, or
inapplicable information.
21. Rule 4: Active Online Catalog Rule
The database catalog, which contains metadata about the
database, must be stored and accessed using the same relational
database management system.
Rule 5: The Comprehensive Data Sublanguage Rule
A crucial component of any efficient database system is its ability
to offer an easily understandable data manipulation language (DML) that
facilitates defining, querying, and modifying information within the
database.
Rule 6: The View Updating Rule
All views that are theoretically updatable must also be updatable
by the system.
22. Rule 8: Physical Data Independence
Application programs and activities should remain unaffected
when changes are made to the physical storage structures or methods.
Rule 7: High-level Insert, Update, and Delete
A successful database system must possess the feature of
facilitating high-level insertions, updates, and deletions that can grant users
the ability to conduct these operations with ease through a single query.
Rule 9: Logical Data Independence
Application programs and activities should remain unaffected
when changes are made to the logical structure of the data, such as
adding or modifying tables.
23. Rule 10: Integrity Independence
Integrity constraints should be specified separately from application
programs and stored in the catalog. They should be automatically enforced
by the database system.
Rule 11: Distribution Independence
The distribution of data across multiple locations should be invisible
to users, and the database system should handle the distribution
transparently.
Rule 12: Non-Subversion Rule
If the interface of the system is providing access to low-level records,
then the interface must not be able to damage the system and bypass security
and integrity constraints.
24. Functional Dependencies
• Functional Dependency (FD) is a constraint that describes
the relationship between attributes in the relation (table).
• FDs and Keys are used to define the normal forms for
relations.
25. Functional Dependencies
Definition :
Relation schema: R {A1,A2,...,An}
X , Y are subsets of R
If R: X Y then,
If t1[X]=t2[X] then,
t1[Y]=t2[Y] in any relation instance r(R)
R
t2
t1
Y
X
27. Examples for FD constraints.
• Student ID determines Student name and Birth date.
StID {StName, Bdate}
• Sport Name determines type of sport.
SpName type
• Student ID and Sport Name determine the hours per week that
the student practices his sport.
{StID, SpName} hours
28. Functional Dependencies
• A FD is a property of attributes in the relational schema R
(intension).
• If L is a key of the relation R, it determines all the attributes of
R.
29. Inference Rules for FDs.
• Armstrong's inference rules
A1. (Reflexive) If Y subset-of X, then X Y
A2. (Augmentation) If X Y, then XZ YZ
(Notation: XZ stands for X U Z)
A3. (Transitive) If X Y and Y Z, then X Z
30. Additional Useful Inference Rules.
• Decomposition
If X YZ, then X Y and X Z
• Union
If X Y and X Z, then X YZ
• Psuedotransitivity
If X Y and WY Z, then WX Z
32. 1. Trivial Functional Dependency.
• The dependency of an attribute on a set of attributes is known
as trivial functional dependency if the set of attributes includes
that attribute.
If B is a subset of A then,
ABB
AA
BB
A B
33. 2. Non-Trivial Functional Dependency.
• If a functional dependency X->Y holds true where Y is not a
subset of X
If B is not a subset of A then,
AB
A B
34. 3. Multi-valued Dependency.
• If there are more than one independent multi-valued attributes
in a relation, that is called “multi-valued dependency”.
bike_model manf_year colour
V001 2011 Black
V001 2011 Blue
V002 2012 Black
V002 2012 Blue
V003 2013 Black
V003 2013 Blue
bike_model ->> manf_year
bike_model ->> colour
35. 4. Transitivity Dependency.
• A functional dependency is said to be transitive if it is indirectly
formed by two functional dependencies.
Transitive dependency: XZ;
if the following three functional dependencies hold TRUE,
XY
Y does not X
YZ
• Can only occur in a relation of three or more attributes.
• Helps to normalizing the DB in 3NF.