The SQL vs NoSQL

Sam Ghoreishi
5 min readApr 15, 2019

A brief introduction

SQL or Rational database management system RDBMS

MySQL database table viewed using phpMyAdmin

Rational Databases were introduced in 1970s to to deal with first wave of data storage applications through a standard data modelling and query language (Structured Query Language, or SQL).

RDBMS organises data into one or more tables of columns and rows with a unique key identifying the each row.

A column is basically a property of the table.

For example, a table could have 3 columns: ID, First Name, Last Name.

Designer view of a typical MySQL database

SQL Database tables have Schema which is basically a blueprint and defines how the data is organised structure the database and prevent invalid datas to be entered into database.

Rows in a table can be linked to rows in other tables by adding a column( foreign keys) for the unique key of the linked row.

Some of the well know SQL databases are MySQL, Postgres, Microsoft SQL Server and Oracle Database.

Lets imagine we have a table with 3 columns of “first_name”, “last_name” and “user_name ” and I need to enter “email_address” into the data, Schema prevent this operation and I get error message as there is no column called “email_address” so I need to create this column before I am able to enter. This ALTER statement to change the table structure adds the constraint stating it can’t be Null. To fix this issue we need to add the column without the NOT NULL constraint and manually enter the “email_address” value for all the existing rows and then ALTER the table to add the NOT NULL constraint into the table.

If you are developing a new App you may not know exactly what is your database Schema or when you complete a new features, the schema of your database often needs to be changed so you can imagine how hard it would be to constantly go back to database and Alter the tables and Schema.

That where NOSQL databases comes into play

What is NOSQL database?

A NOSQL or as it was originally referred to, “non SQL” or “non relational” database provides a mechanism for storage and retrieval of data that is modelled in means other than the tabular relations used in relational databases.

NoSQL database is basically a huge JSON file hosted in the cloud. it’s just a combination of key/value pairs and has no schema for the database, no tables, no columns

How user table in NOSQL would look like

NOSQL Databases are Schema_less databases which basically means they have no structure which bring lots of flexibilities.

Going back to our email_address example, we can simply add “email_address” value to one of our entries without the need to change the schema of the the database or changing the value of the current entries.

This is really great for flexibility but doesn’t really help us ensure data integrity.

NOSQL databases such as MangoDB or Google’s Firebase provide security roles to validate data and you can define the child entry value to to be, String, Number etc. This is similar to constraint is SQL.

The main difference between SQL database and NOSQL database is the flexibility and integrity, SQL has lots of integrity but NOSQL database has lots of flexibility and the integrity of the database are left to developer to deal with.

There are other advantages on using NOSQL database

since rational databases were designed in 70s and never designed to cope with current volume of datas there are restriction on performance for example:

  • Elastic scalability:

SQL databases are vertically scalable whereas the NoSQL databases are horizontally scalable. SQL databases are scaled by increasing the resources of the hardware by improving the CPU, RAM, SSD, etc, on a single server. A database administrator can simply add more commodity servers or cloud instances. The database automatically spreads data across servers as necessary.

  • Big data applications:

NoSQL database fits better for the hierarchical data storage as it follows the key-value pair way of storing data similar to JSON data. NoSQL database are highly preferred for large data set.

  • Database administration:

SQL databases require administrators to design, manage and maintain the system Most NoSQL databases also support automatic replication, meaning that you get high availability and disaster recovery without involving a team to manage these tasks.

Closing thoughts:

NOSQL databases are fairly new comparing to SQL databases which have been around since 70s so there are still many obstacles which must be overcome before they can be fully accepted and used by many more well stablished organisations. Many of the developers using the system are still in the learning stage and therefore the community support is also limited.

Any organisation or developer willing to implement NoSQL solutions needs to proceed with caution, bearing in mind the above limitations but since NOSQL was designed with the demands of the Web 2.0 modern-day web applications in mind its worth learning implementing in small projects.

ref:

--

--