SQL VS NOSQL
SQL VS NOSQL
What is NoSQL?
• NoSQL, or most commonly known as Not only SQL database, provides a
mechanism for storage and retrieval of unstructured data.
• This type of database can handle a humongous amount of data and has a
dynamic schema.
• So, a NoSQL database has no specific query language, no or a very few
relationships, but has data stored in the format of collections and
documents.
So, a database can have a ‘n’ number of collections and each collection can have
‘m‘ number of documents. Consider the example below.
SQL vs NoSQL
1. Type of Database
2. Schema
3. Database Categories
4. Complex Queries
5. Hierarchical Data Storage
6. Scalability
7. Language
8. Online Processing
9. Base Properties
10. External Support
Type of database
Schema
• SQL needs a predefined schema for structured data. So, before you start
using SQL to extract and manipulate data, you need to make sure that your
data structure is pre-defined in the form of tables.
• NoSQL, have a dynamic schema for unstructured data. So, if you are using
a NoSQL database, then there is no pre-defined schema present, and the
complete schema of your data completely depends upon how you wish to
store data. i.e. which fields do you want to store in documents and
collections.
Database Categories
• The SQL databases are table based databases. So, you can have ‘n’ number
of tables related to each other and each table can have rows and columns
which store data in each cell of the table.
Now, if we talk about NoSQL Databases, then NoSQL databases have the following
categories of databases:
So, SQL databases store data in the form of tables and NoSQL databases store
data in the form of key-value pair, documents, graph databases or wide-column
stores.
Complex Queries
SQL is a better fit for complex query environment when compared to NoSQL as
the schema in SQL databases is structured and has data stored in a tabular
format. So, even if you wish to apply nested queries with many subqueries inside
the outer query, you can easily do by using the proper table and column names.
Now, the reason why NoSQL databases isn’t a good fit for complex queries is
because the NoSQL databases aren’t queried in a standard language like SQL.
Scalability
• The SQL databases are vertically scalable. You can load balance the data
servers by optimizing hardware such as increasing CPU, RAM, SSD, etc.
• On the other hand, NoSQL databases are horizontally scalable. You can
perform load balancing by adding more servers to your cluster to handle a
large amount of traffic.
Language
• The SQL databases have a specific language, and it does not vary from
databases to databases. This kind of databases uses the SQL ( Structured
Query Language ) for retrieving and manipulating the data.
• The NoSQL databases have no specific language used for queries, and it
varies from database to database. In the NoSQL database, the queries are
mainly focused on the collection of documents and the language is known
as UnQL (Unstructured Query Language).
Online Processing
Base Properties
• SQL databases are based on ACID properties ( Atomicity, Consistency,
Isolation, and Durability) whereas the NoSQL databases are based on
the Brewers CAP theorem ( Consistency, Availability, and Partition tolerance
).
ACID properties
CAP Theorem
Brewers CAP Theorem states that a database can only achieve at most two out of
three guarantees: Consistency, Availability and Partition Tolerance. Here
• Consistency: All the nodes see the same data at the same time.
• Availability: Guarantees whether every request is successful in failed.
• Partition Tolerance: Guarantees whether a system continues to
operate despite message loss or failure of part of the system.
Now, the most popular databases from SQL and NoSQL are MySQL and MongoDB.
MySQL vs MongoDB