0% found this document useful (0 votes)
2 views

lecture 4_

Relational Algebra is a formal framework for defining how relational databases operate, serving as an interface to the data and underpinning SQL operations. It includes various operators for data manipulation such as INSERT, DELETE, and MODIFY, as well as retrieval operations like UNION, INTERSECT, and JOIN. The document outlines the theoretical functions of relational algebra and their application in database management systems.

Uploaded by

kbjoash
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

lecture 4_

Relational Algebra is a formal framework for defining how relational databases operate, serving as an interface to the data and underpinning SQL operations. It includes various operators for data manipulation such as INSERT, DELETE, and MODIFY, as well as retrieval operations like UNION, INTERSECT, and JOIN. The document outlines the theoretical functions of relational algebra and their application in database management systems.

Uploaded by

kbjoash
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Relational Algebra

Relational Database
Operators
Introduction

In order to implement a DBMS, there must exist a set of rules


which state how the database system will behave.
For instance, somewhere in the DBMS must be a set of
statements which indicate than when someone inserts data
into a row of a relation, it has the effect which the user
expects.
One way to specify this is to use words to write an `essay' as
to how the DBMS will operate, but words tend to be imprecise
and open to interpretation. Instead, relational databases are
more usually defined using Relational Algebra.
Relational Algebra is :
 the formal description of how a relational database
operates
 an interface to the data stored in the database itself
 the mathematics which underpin SQL operations
Operators in relational algebra are not necessarily the
same as SQL operators, even if they have the same
name. For example, the SELECT statement exists in SQL,
and also exists in relational algebra. These two uses of
SELECT are not the same.
The DBMS must take whatever SQL statements the user
types in and translate them into relational algebra
operations before applying them to the database.
Operators

Operators - Write
 INSERT - provides a list of attribute values for a new tuple in a
relation. This operator is the same as SQL.
 DELETE - provides a condition on the attributes of a relation to
determine which tuple(s) to remove from the relation. This operator is
the same as SQL.
 MODIFY - changes the values of one or more attributes in one or
more tuples of a relation, as identified by a condition operating on
the attributes of the relation. This is equivalent to SQL UPDATE.
Operators - Retrieval
There are two groups of operations:
 Mathematical set theory based relations:
UNION, INTERSECTION, DIFFERENCE, and CARTESIAN PRODUCT.
 Special database operations:
SELECT (not the same as SQL SELECT), PROJECT, and JOIN.
Relational Functions

 The degree of relational completeness


can be defined by the extent to which
relational algebra is supported.

 Relational algebra defines the theoretical


way of manipulating table contents using
the eight relational functions: SELECT,
PROJECT, JOIN, INTERSECT, UNION,
DIFFERENCE, PRODUCT, and DIVIDE.
UNION
 UNION combines all rows from two tables.
The two tables must be union compatible.
INTERSECT
 INTERSECT produces a listing that
contains only the rows that appear in
both tables. The two tables must be union
compatible.
DIFFERENCE

 DIFFERENCE yields all rows in one table


that are not found in the other table; i.e.,
it subtracts one table from the other. The
tables must be union compatible.
PRODUCT

 PRODUCT produces a list of all possible


pairs of rows from two tables.
SELECT

 SELECT yields values for all attributes found in a


table. It yields a horizontal subset of a table.
PROJECT
 PROJECT produces a list of all values for selected
attributes. It yields a vertical subset of a table.
JOIN

 JOIN allows us to combine information


from two or more tables. JOIN is the
real power behind the relational
database, allowing the use of
independent tables linked by common
attributes.
NATURAL JOIN

 Natural JOIN links tables by selecting


only the rows with common values in
their common attribute(s). It is the
result of a three-stage process:
 A PRODUCT of the tables is created. (Figure
2.12)
 A SELECT is performed on the output of the
first step to yield only the rows for which the
common attribute values match. (Figure 2.13)
 A PROJECT is performed to yield a single copy
of each attribute, thereby eliminating the
duplicate column. (Figure 2.14)
Natural Join, Step 1: PRODUCT

Figure 2.12
Figure 2.13 Natural Join, Step 2: SELECT

Figure 2.14 Natural Join, Step 3: PROJECT


DIVIDE

 DIVIDE requires the use of one single-


column table and one two-column table.

You might also like