CH 2
CH 2
Syllabus:
Entities & Attributes, Entity types, Key Attributes, Relationships, Domains, Tuples, types of Attributes, Relations, Character-
istics of Relations, Keys, Attributes of Relation, Relational Database, Integrity Constraints. Relational Algebra: Concept and
Relational Algebra operations like Select, Project, Join, Division, Union etc.
3 Relational Algebra
Relational algebra is a mathematical language that is used to manipulate and query relational data. It provides a set of basic
operations for transforming and retrieving data stored in relational databases. The relational algebra operations are performed
on relations, which are similar to tables in relational databases.
Relational algebra was first introduced by E. F. Codd in 1970 as part of his work on the relational model for data management.
It provides a declarative way of expressing data retrieval and manipulation operations, which makes it easy to understand and
implement.
Relational algebra operations include selection, projection, union, intersection, difference, join, and others. The selection
operation is used to filter data based on certain conditions, while the projection operation is used to select specific columns from
1
a relation. The union operation is used to combine the data from two or more relations, while the intersection operation is used
to retrieve data that is common to two or more relations. The difference operation is used to retrieve data that is unique to one
relation but not the other.
Relational algebra is a foundational concept in the field of database management and is used as the basis for many query
languages, such as SQL. It provides a clear and concise way of expressing data operations and is widely used in the design and
implementation of relational databases.
In conclusion, relational algebra is a powerful tool for managing and manipulating relational data. Its declarative syntax
makes it easy to understand and use, and its wide use in the field of database management makes it an essential concept for
anyone working with relational databases.
• Data integration: Relational algebra can be used to combine data from multiple relational databases into a single
integrated view. The operations in relational algebra, such as union and join, can be used to combine data from different
relational databases into a single view.
• Data transformation: Relational algebra can be used to transform relational data from one form to another. For
example, relational algebra can be used to transform data from a wide relational table to a tall relational table or vice
versa.
• Data analysis: Relational algebra can be used to perform data analysis on relational data. The operations in relational
algebra, such as projection and aggregation, can be used to summarize and aggregate data, making it easier to perform
data analysis and gain insights into the data.
In summary, relational algebra provides a powerful and flexible tool for manipulating relational data, making it a key component
in the management and analysis of relational databases.
2
• Projection (π): Selects columns from a table. For example, ”Π(name, age) (R) would select only the name and age
columns from relation ”R”.
• Rename (ρ): Changes the name of a relation, column, or attribute.
• Union (∪): Returns all the rows from two tables that have the same structure, and removes duplicates.
• Intersection (∩): Returns all the rows that appear in both tables.
• Difference (−): Returns all the rows that appear in one table and not in the other.
• Cartesian Product (×): Returns all possible combinations of rows from two tables.
• Join (▷◁): Combines rows from two tables based on a common column. For example, you could join a table of customers
with a table of orders to find all orders made by a particular customer.
• Divide (÷): Returns all the rows from one table that are not associated with any row in the other table.
• Aggregation (Σ): Summarizes data by performing operations such as counting, averaging, or summing. For example,
you could use aggregation to find the total sales for a particular product.
These basic operations can be combined in various ways to perform more complex tasks, such as finding the average quantity of
products purchased by each customer. By using relational algebra, you can perform complex data manipulations and queries in
a concise and formal way, which makes it easier to understand, maintain and extend your code.