0% found this document useful (0 votes)
44 views10 pages

Relational Algebra

The document discusses relational algebra and the relational data model. It defines relational algebra and its operators like select, project, rename, union, set difference, and cartesian product. It also explains concepts of the relational data model including tables, attributes, tuples, domains, and constraints.

Uploaded by

coolscools123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views10 pages

Relational Algebra

The document discusses relational algebra and the relational data model. It defines relational algebra and its operators like select, project, rename, union, set difference, and cartesian product. It also explains concepts of the relational data model including tables, attributes, tuples, domains, and constraints.

Uploaded by

coolscools123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

 Relational Algebra is a procedural query language.

 Relational algebra mainly provides a theoretical foundation for


relational databases and SQL.
The operators in relational algebra are classified as-

Relational Data Model : The Concept

 Relational data model represents the logical view of how data is stored in the
relational databases. There exists some concepts related to this, which includes
the following terms.

1. Table : In relational data model , data is stored in the tables. The tables
consists of a number of rows and columns. Thus, table is used because it can
represent the data in the most simplest form possible making data retrieval
very easy.

2. Attribute : Any relation have definite properties that are called as attributes.

3. Tuple : Rows of table represents the tuple which contains the data records.
4. Domain : Domain is a set of values which is indivisible i.e. value for each
attribute present in the table contains some specific domain in which the value
needs to lie. For Example : The value of date of birth must be greater than zero.
As, it cannot be negative.

5. Relation : A relation in relational data model represents the respective


attributes and the correlation among them.

Any relation can be denoted by : R(A1, A2, A3,…,An)

where, R Represents relation name and A1, A2, A3,…,An represents the attributes
present in the relation.

 Let’s make this concept clear with an example : Consider a relation R(Roll
No, Class, Marks, Age) having some attributes as mentioned. The concept
can be drawn as:

Relational Data Model: Example


Relational Data Model : Constraints

 The constraints in the relational data model are the rules and conditions that
need to be followed. These rules and conditions ensures that the relation is
valid and any changes or alterations made on data will not affect its operation.
 There are three major constraints based on the relational data model which are
explained below.

Relational Data Model : Constraints

1. Domain Constraint : This constraint is mainly applicable on the value of


attributes present in the table. It ensures that the values are legitimate and
comes within a pre-specified domain.

For example : Name of a person cannot contain digits (0 to 9) or special


characters and Age of a person cannot be negative.

2. Key Constraint : The key constraint ensures that a table representing a


relation, any row/tuple can be fetched directly using a single unique attribute
called as a key. There might be a situation where, combination of multiple
attribute may act as a key also.

For example : Consider a relation R(Roll No, Class, marks, Age) having some
attribute. If we want to fetch the details of any student, with the help of a key it
can be done.

Relational Data Model: Key Constraints


3. Referential Integrity Constraint : The referential integrity works on the
concept of foreign key. A foreign key is nothing but an attribute that is
commonly linked between two relation using that same attribute. Both the
relations/tables must contain the same attribute.

For example : Consider two relations R1(Roll No, Name, Marks) and R2(Roll No,
Address, Age) of students of a school. Roll No being the common attribute will
act as a key for relation R1 and can reference to Roll No attribute of relation
R2 with the help of which any tuple can be retrieved from the tables.

Relational Data Model: Referential Integrity Constraints

Relational Algebra : Introduction


 The relational algebra provides basic operations which can be performed over
single or multiple relations in order to generate new relations(single or
multiple). Relational algebra is a procedural query language which follows a
particular syntax with the help of which, data can be accessed and retrieved
very easily from single as well as multiple table/data sources.
 Certain operators are used to perform queries and retrieve desired results.
These operators can perform certain operations on single attribute(called unary
operator) or multiple attribute(called binary operator).
 There are six different types of operator that can be used to perform different
operations. All of these are listed and explained below.
Relational Algebra : Operations

Relational Algebra : Operations


1. The Select Operation : This operation is used to fetch rows from given table
or relation on the basis of given conditions, it is denoted by “Sigma(σ)”.

Syntax : σ <Condition> (Relation Name)


Here, “σ” is the select operation symbol. R is the relation from which the data
needs to be fetched on the basis of conditions. Also, relational operators such
as =, <, > etc. can also be used along. Let’s look at the example to get a clear
picture of this.

Example:

A B C

1 2 3

4 5 6

7 8 9

6 5 4
σ(c>3)R will select the tuples which have c more than 3.

A B C

4 5 6

7 8 9

6 5 4

Note: The selection operator only selects the required tuples but does not display
them. For display, the data projection operator is used.

For example : Consider the table of relation R(Roll No, Name, Age, Marks). If
we want to select the name and age of student, then it can be done by:

Query Used : σ Name and Age>21 (Student_Details)

Relational Algebra: Select Operation


2. The Project Operation : This operation is also used to fetch all the
rows/tuples/data according to the requested attribute. It means, using project
operation one can simply fetch all the tuples corresponding to a single attribute
or multiple attributes. It does not supports any conditions as select operation
and is denoted using “Pie(π)”.

Syntax : π<attribute>(Relation Name)

π(B,C)R will show following columns.

B C

2 4

2 3

3 4

For example : Consider the table of relation R(Roll No, Name, Age, Marks). If
we want to project the marks column, then it can be done by :

Query Used : πMarks(Student_Details)

Relational Algebra: Project Operation


3. The Rename Operation : When operations like project and select are
performed to fetch new results, these results requires renaming. They can be
renamed using the rename operation which is denoted using Greek letter
“Rho(ρ)”.

Syntax : ρ<New Name>(New Relation)

4. The Union Operation : In order to fetch data from two relations to generate
new relation with combined capabilities, union operations can be used. The
union operation fetches the data from both tables and projects it accordingly. It
is denoted through “Union Symbol(U)”. Also, two things need to keep in mind
while applying union operation are :

 Both the relations compulsory to have same number of attributes.


 Both the relations compulsory to have same domain for attributes.

Syntax : X1 U X2 , where X1 & X2 are two different relations satisfying the above two
conditions.

For example : Consider the two tables with relations X1(Name, Age) and
X2(Name, Age). If we wish to apply the union operation, then it can be done by :

Relational Algebra : Union Operation

5. The Set Difference Operations : In order to fetch the data which is not
present in any one of the relation, set difference operation is used. The set
difference operation is denoted by “Minus(-)”.

Syntax : X1 - X2 or X2 - X1 , where X1 & X2 are two different relations having some


attributes.
Note : X1 - X2 ≠ X2 - X1 {Not Commutative}
For example : Consider the two tables with relations X1(Name, Age) and
X2(Name, Age). If we wish to apply the set difference operation, then it can be
done by :

Relational Algebra : Set Difference Operation


6. Cartesian Product : The Cartesian product operation will generate the
possible combinations among the tuples from the relations resulting in table
containing all the data. It combines the information of two or more relations in
one single relation. Cartesian product is different from union operation and is
denoted by “Cross(X)”.

Syntax : A1 - A2 , where A1 & A2 are two different relations having some attributes.
For example : Consider the two tables with relations A1(Name, Roll No)and
A2(Name, Roll No). If we wish to apply the Cartesian product operation, then it
can be done by :

You might also like