DEV Community

Cover image for Relational Algebra: The Best Kept Secrets for Efficient Data Management
Pragyan Tripathi
Pragyan Tripathi

Posted on

Relational Algebra: The Best Kept Secrets for Efficient Data Management

Relational Model and Relational Algebra are fundamental to getting the most out of DBMS. This post will save you hours if you are pursuing a career in data analytics and learning about databases.

Relational Algebra

Vedika found that Ted Codd's paper on the Relational Model was revolutionary and that modern databases such as Postgres, Oracle, and MySQL are based on it.

To delve further, she needed to understand Relational Algebra, the fundamental concept that empowers DBMS to query the database.

To manage data in Relational Model, it adheres to three simple concepts:

  1. Structure: Definition of Relation and their contents
  2. Integrity: Ensure contents in the database satisfy provided constraints
  3. Manipulation: How to access and modify a database's contents.
  • A Relation is an unordered set containing the relationship of attributes representing entities.

  • Since the relationships are unordered, DBMS can store them in an optimised way.

  • A Tuple is a set of attribute values in a relation.

Basic Definitions

  • A relation has a Primary Key that uniquely identifies a single Tuple. Some DBMS create it automatically.

  • Relations can also define Foreign Key, which specifies how an attribute from one relation has to map to a tuple in another.

To interact with data you use Data Manipulation Language (DML)
DML languages are of two types:

  1. Procedural: Specifies the strategy the DBMS should use to find the desired result (Relational Algebra)
  2. Declarative: Specifies what data is needed and not how to find it (Relational Calculus)

Relational Algebra includes 7 fundamental operations to retrieve and manipulate tuples in a Relation.
Each operator inputs one or more relations and outputs a new relation.
To write complex queries you can chain them together to create more complex operations.

Fundamental Operators in Relational Algebra

Relational Algebra is procedural because you need to specify a sequence of operations that must be performed to manipulate data in a database.

A better approach would be for the user only defines the data he needs and for DBMS figures out the best execution strategy.

DBMS implements Relational Algebra under the hood, exposing a declarative language like SQL to interact with it.

The Relation Model in its essence is independent of any query language implementation.

But SQL became the de facto standard to represent it and interact with DBMS.

Introducing SQL

The beauty of the Relational Model is in its ability to separate data from storage and interaction methods.
With SQL becoming the standard for interacting with relational databases, Vedika plans to delve into it next.

To keep up with her journey, follow me @pragyanatvade and check out the previous post here

Top comments (0)