Relational vs Non-Relational Database | Simple Explanation πŸš€

Subscribe to my newsletter and never miss my upcoming articles

Hey there, welcome to another blog! So recently I got really interested in understanding the clear difference between a Relational/SQL and a Non-relational/NoSQL database so that I could explain it to anyone confidently. πŸ™‹β€β™‚οΈ

So, I read a bunch of blogs, worked on it and now I'm going to explain it in very simple words so that you can easily understand the difference between both and moreover I also show the pros and cons and which database should you use or learn. πŸ“Œ

ezgif-2-264872b39212.gif

Relational Database πŸ‘©πŸΌβ€πŸ€β€πŸ§‘πŸ½ :

This type of database model organizes data into one or more tables which obviously consists of columns and rows. And each row is associated with a unique key. Here Rows are also called records or tuples and Columns are also called attributes.

Relational databases are also called SQL databases where "SQL" stands for Structured Query Language and it’s the language relational databases are written in. SQL is used to execute queries, retrieve data, and edit data by updating, deleting, or creating new records.

Example Languages: PostgreSQL, sqlite3, SQL , MySQL,

relational theory.png

Advantages:

  • So there is a set of properties called ACID which stands for - Atomity, Consistency, Isolation, Durability and this ensures reliable database transactions. And these RDBMS are really good at this.

  • It can handle lots of complex queries, database transactions, and routine analysis of data as the data in tables are very well connected/related with the help of unique keys.

Disadvantages:

  • Fixed Schema: RDBMS(Relational Database Management System) was designed to store mainly static data thus being stored in tables so, that does not make the manipulation of schema or model very flexible as it is in a Non-relational DB. One can't store complex or very large images, numbers, designs, and multimedia products.

  • Scalability Issues: These are hard to scale as they need more servers to scale up and thus a lot of money. Imagine you have massive user growth, then a RDBMS is more difficult to scale as compared to a Non-relational database.

Now the Non-relational databases especially solve these two problems which makes them very adaptable so let me tell you about those.

Non-Relational Database πŸ§β€β™‚οΈ :

A non-relational database is any database that does not use the tabular schema of rows and columns like in relational databases. Instead, guess what- its storage model is optimized for the type of data it is storing. It is that flexible!

Non-relational databases are also known as NoSQL databases which stands for β€œNot Only SQL.” That brings me to a great point that you don't need to use just SQL to query the database instead you can use any language of your choice. Like Hashnode is going to do the moment I publish this article, probably using Javascript. Correct me if I'm wrong! πŸ˜„

Some types of NoSQL DBs :

  • Document Store :

    Here documents are stored in the database with a unique key associated with each document. And you can query and manipulate the database just by sending an API request using any language and not just SQL as we discussed earlier.

    One of the best examples is MongoDB which I also use and is the first database I learned to use. The best part about it that I love is that it stores the documents in JSON-like format so it becomes really familiar in a short time.

    MongoDB allows for auto-sharding which is a type of database partitioning that separates very large databases into smaller, faster, more easily managed parts called data shards. This is what helps it scale up fast and in a cost-friendly way without needing to add more servers.

  • Key-Value Store :

    This stores data as a collection of key–value pairs, such that each key appears at most once in the collections. So this is kind of based on data structures like maps or dictionaries.

    One of it great example is Redis - short for Remote Dictionary Server which is being extensively used now and I guess it is also Opensource.

  • Graph Database :

    This database is mainly based on Graph data structure. This stores data in a graph-like model such that the data with similar characteristics or attributes can be interconnected or caught quickly which can be used to find insights various.

Facebook used MySQL which a Relational Database earlier but then it made a Graph database of it's own which helped them make these great connections between users.

1566472262617.gif

The Main Question - What Database Should I Use ? :

Okay, so from what I have learned since these past days I will suggest that if you are a beginner trying to make projects on the web or a Startup and you can't afford to throw a lot of money on servers then a Non-Relational Database is best for you. And also it helps because in this scenario you are very flexible with the data you store so NoSQL helps.

If you are a beginner I would suggest going with MongoDB as it also offers a free tier for personal projects.

And if you need to store and retrieve data or perform heave read and write operations, a Relational or SQL database is best for you. And this is the reason why Data Scientists use SQL databases, as their data is static and does not need to vary as they just need the pre-built data to train Machine Learning models.

I am no expert I'm still learning each day so ya just research a lot and use whatever your work demands.

This table might help you a lot !

6433.sql vs nosql.jpg

Aaand... this is the video version of the blog where I also explain the database with an example πŸ“š:

I hope you learned something from the blog, Do comment and let me know your thoughts on !

I also create videos on Youtube at - Future Driven and also active on Twitter .

Let's Connect, Stay safe & Have a great day! πŸ§‘πŸš€

Comments (2)

Edidiong Asikpo's photo

This was very well explained and straight to the point. Love it!

Saumya Ranjan Nayak's photo

Thanks Edidiong, means a lot !