Relational Algebra: The Best Kept Secrets for Efficient Data Management
Tags: database, backenddevelopment, devjournal, programming
Published: 2023-03-02 05:44:24

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2yyam7vpbv8itc3t0yt9.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d6p1d8c86retagpmp7rs.png)



- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fj7ep0rfk263v38xten.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8i8p7qjsty6pz2lkh62x.png)

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](https://dev.to/pragyanatvade/want-to-level-up-your-skills-and-unlock-the-power-of-databases-2nbi)