SQL vs NOSQL

Isuri Punchihewa
5 min readApr 19, 2021

What is the difference between SQL and NoSQL??

Before exploring about SQL Let’s gain a proper understanding about Relational Database and a Relational Database Management Systems (RDBMS).

Relational Database

Relational database is refers to a database which stores data in a structured format by using columns and rows. This structure provides easy access towards data within the database.

As the values within each table are related to each other this is considered as “relational”. Furthermore tables also can be related to other tables.

Relational Database Management System(RDBMS)

Database Management System(DBMS) is a software system which uses a standard method of cataloging, retrieving and running queries on data. DBMS manages incoming data, organizes them, allows users to modify and extract data whenever necessary.

Relational Database Management System(RDBMS) is a subset of DBMS which is specifically designed for relational databases. To be more specific RDBMS is the software that executes queries on the data including inserting, updating and searching for values.

SQL

What is SQL?

SQL stands for Structured Query Language which allows us to interact (store, update, delete and retrieve data) with a specific type of database.

We could store, update, delete and retrieve data from RDBMS by writing queries using SQL.

Relational Databases are consisted with two main characteristics.

  1. Follow a strict data schema when storing data.
  2. Split data among multiple tables which are connected through relations.

Let’s talk about these characteristics in detail.

1.Following a Strict Data Schema

In Relational Database, data is stored in tables which act as storage containers. Each and every table have a clearly defined schema. In the other words every table have a set of fields defining which data can or can not go into the table.

This characteristic prevent you from inserting records which do not fit into the defined schema.

2. Splitting data among multiple tables(Relations)

In order to avoid data duplication we split data into multiple tables. Splitting data depends on the relationships between the tables such as one-to-one relation, one-to-many relation, many-to many relations.

One-to-One Relationship

In one-to-one relationship, one record in a particular table can be associated with a one, just one record in another table.

For an example, in the A/L examination database, a one student has only one examination number, and each student’s examination number is assigned to only one student.

One-to-Many Relationship

In one-to-many relationship, one record in a particular table can be associated with more than one records from another table.

For an example, in a manufacturer database, one manufacturer can manufacture more than one product.

Many-to-Many Relationship

In Many-to-Many relationship, more than one record in a particular table is associated with more than one records from another table.

For an example, in a university database, one student can follow more than one courses and one course can have more than one students.

Examples of SQL Databases

  1. MySQL
  2. Oracle
  3. Db2
  4. PostgreSQL
  5. SQL Server
  6. CockroachDB
  7. YugabyteDB

NoSQL

What is NoSQL?

NoSQL is a non-relational database that stores data and access data using key-values. Which means, in NoSQL database each information stands individually with a unique key.

NoSQL databases do not have tables with rows and columns tolling data values but still they can handle large amount of data. In the below diagram there is an Employee Info database and it has two collections, Employee Collection and Project Collection. Each of these collections has documents which are basically the data values. For a proper understanding we can consider the collections as the tables and the documents as the fields of the tables.

Most importantly data in NoSQL are schemaless, which means that the data in the NoSQL databases does not require to have the same schema. Which means there can be multiple documents in the same collection which has different schemas. This approach is ideal for capturing and storing user generated content including text, images, audio, files, videos or other data. This approach provides a much more flexible approach to storing data than a relational database.

NoSQL databases are more flexible and scalable than the SQL databases. As the database grow bigger the SQL databases become more slower and inefficient. But the NoSQL databases are highly scalable. Thus, you can add many records to a NoSQL databases with a minimal decrease in performance.

Larger businesses have started to use NoSQL databases because of their flexibility and scalability.

NoSQL database does not have a specific language to manipulate data and it varies from database to database. In the NoSQL databases, queries are focused on the collection of documents and sometimes the language used in NoSQL is also called as the Unstructured Query Language.

Examples of NoSQL Databases

  1. MongoDB
  2. CouchDB
  3. Redis
  4. Elasticsearch
  5. Cassandra

That’s simply the basics about the SQL and NoSQL. I hope you all enjoy reading this blog and hope you find this useful. Thank You for reading and Have a nice day!

--

--