SQL vs NoSQL Databases (What to choose!)

Video Tutorial


SQL database structure is a type of database based on the relational data model which creates tables with columns based on its relation the main benefit is reducing data redundancy and have a table/column database structure.

SQL (Structured Query Language) is also a programming language used to Manipulate and communicate with a Relational Database (Insert, Save, Sort, Delete…) data.

Many of you may know SQL from MySQL the famous SQL database management system (DBMS) which uses the SQL language for data manipulation, where most of the DBMS use SQL as their main language for allowing client interaction and handling database queries.

Take a Look on the SQL Tables below which represents a Student and a Course that a student(s) can take where multiple courses can be taken by a single student.

The First table which is highlighted in orange is a table that we created out of our mind without applying any rules of a relational database.

As you can see each table in SQL DBMS there is a unique ID which uniquely identifies each record saved on the table also, each column in the table has to have a relation with the table itself, for ex: here we have a student table so every column has to have some kind of relation to this student otherwise, this becomes non-relational and it makes everything about SQL databases goes the wrong way.

The Courses Column is the wrong column that should not exist in the Student table cause for each column their has to be one single value (and here it has multiple courses) plus a course needs its own table that represents the needed data for each student taking whatever course his enrolled in.

In this case, we need to split up the first table into two tables, one for the student itself and the other going to represent the course and which user(s) are taking this course and we link this two tables with a SQL Relation and that what the whole system is based on.

we put the unique Course ID in the student table to identify which Course(s) are being taken by this user, and also, we put the Student ID in the Course table to tell it which Student(s) are taking this course.

Of course when you create a new SQL table you always need to assign it with an ID and likely DBMSs allows you to do that automatically by assigning it for you without you even noticing you just have to specify the initial configuration for how ID is uniquely generated depending on your table needs then everything is going to be automated.

And since a single Student can take multiple courses where a course can be taken by multiple users this tells us that there is a Many-to-Many Relationship where there are other types of relationship between tables or what’s actually called (Entity).


NoSQL basically stands for a non-relational database which is exactly what it says from its name no relations between data entities on the database where each entity is an Object (ex: javascript Object) this object can hold all the data it needs without holding links to other relational data (like we did in tables) and this where it powers comes from.

Mostly used for large data and singleton systems (for ex: Social Networks) where each user has his own info and interaction (likes, tweets, retweets…).

on NoSQL context, there is no such thing as tables so here is the schema

Database --> Collection(s) --> Objects(s)

Collections in the case of NoSQL databases are the same as tables but they have no relations with other collections at least of what you know about SQL Relations.

Take a look on the below example of an Object holding a data of a Student how can study multiple courses.

As you can clearly see it has the same representation of a javascript Object or JSON and the main important notice is that the Object holds a Key-Value pair so in the case of NoSQL databases without the key of the pair you need to access you cannot access to view or change the data.

Like SQL databases it also has a unique ID which uniquely identifies the Object stored inside of the collection.

The Major part is about non-relational, as you can see that we stored the data of the courses being taken by the current student in the same object as the student information unlike SQL databases where we need to use relations and move the course into a separate table, NoSQL allows you to store all the related data in one single object but you need to respect the defined Schema of the Object.

Also, nested Object or arrays are supported two you can easily store an array inside of your object or object inside of other objects that is pretty much possible.


Now the biggest question that most of you would ask is which one is better?

The shortest and the sweetest answer to this common question is: it depends on you and your project.

Here are some key factors of where you should consider using one over the other depending on what your project needs.

SQL Databases

  • Relational (Tables/Columns)

  • Complex Queries and Data Fetching

  • Data Availability and Consistency

  • Mostly used for One Server Data Storage

NoSQL Databases

  • Object-Based (Key-Value Pairs)

  • Designed for a Large Amount of Data (SN)

  • Performance Friendly

  • Easily Scalable on Multiple Servers (Clusters)

If you still a bit confused about how to choose, I advice you to watch the video above for more clear point of view and on what conditions you should select you Type of Database to work with on your project.

No Comments Yet