0% found this document useful (0 votes)
12 views9 pages

SQL VS NOSQL

Uploaded by

kvuit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

SQL VS NOSQL

Uploaded by

kvuit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

What is SQL?

• SQL -Structured Query Language is the core of the relational database


which is used for accessing and managing the databases.
• This language is used to manipulate and retrieve data from a structured
data format in the form of tables and holds relationships between those
tables. The relations could be as follows:

• A One-to-One Relationship is when a single row in Table A is related to a


single row in Table B.
• A One-to-Many Relationship is when a single row in Table A is related to
many rows in table B.
• A Many-to-Many Relationship is when many rows in table A can be related
to many rows in table B.
• A Self -Referencing Relationship is when a record in table A is related to the
same table itself.

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

• SQL is called a relational database as it organizes structured data into


defined rows and columns, with each table being related to the other tables
in the database.
• NoSQL, on the other hand, is known as a non-relational database. This is
because data is stored in the form of collections with no or few relations
between them.

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:

• Document Database– It pairs each key with a complex data structure


known as the document. It can contain many different key-value pairs, or
key array pairs or even nested documents
• Key value stores– They are the simplest NoSQL databases. Every single item
in the database is stored as an attribute name or key together with its value.
• Graph store– They are used to store information about networks, such as
social connections. Graph stores include Neo4J and HyperGraphDB.
• Wide column stores– Wide column stores such
as Cassandra and HBase are optimized for queries over large datasets, and
store columns of data together, instead of rows.

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.

Hierarchical Data Storage


Well, when we compare the databases on this factor, NoSQL fits better for
hierarchical storage when compared to SQL databases.

• This is because as the number of tables increases, the complexity of


maintaining relations between them also keeps increasing.
• So, in such a scenario, you cannot relate the humongous amount of tables
with many columns in them to each other.
• But, when you consider a NoSQL database, this kind of database fits better
for the hierarchical data storage as it follows the key-value pair way of
storing data which is similar to JSON data.

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

• SQL databases are used for heavy-duty transactional type


applications. Well, this is because SQL provides atomicity, integrity, and
stability of the data.
• Also, you can use NoSQL for transactions purpose, but, it is still not stable
enough in high load and for complex transactional applications.

• SQL is mainly used for OLTP(Online Transactional Processing) and NoSQL


is mainly used for OLAP(Online Analytical 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

• Atomicity: Atomicity refers to the transactions that are completely done or


failed where transaction refers to a single logical operation of a data. It
means if one part of any transaction fails, the entire transaction fails and
the database state is left unchanged.
• Consistency: Consistency ensures that the data must meet all the
validation rules.Transaction never leaves the database without completing
its state.
• Isolation: The main goal of isolation is concurrency control.
• Durability: Durability means that if a transaction has been committed, it
will occur whatever may come in between such as power loss, crash or any
sort of error.

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.

NoSQL cannot provide consistency and high availability together.

Key Areas SQL NoSQL


Type of database Relational Database Non-relational Database
Schema Pre-defined Schema Dynamic Schema
Document-based
databases, Key-value
Database Categories Table based Databases
stores, graph stores, wide
column stores
Not a good fit for complex
Complex Queries Good for complex queries
queries
Hierarchical Data Fits better when compared
Not the best fit
Storage to SQL
Scalability Vertically Scalable Horizontally Scalable
Unstructured Query
Language Structured Query language
language
Online Processing Used for OLTP Used for OLAP
Base Properties Based on ACID Properties Based on CAP Theorem
Excellent support is
Rely on community
External Support provided by all SQL
support.
vendors
Table 1: Differences between SQL and NoSQL – SQL vs NoSQL

Examples of SQL and NoSQL


Examples of SQL and NoSQL are as follows:

Now, the most popular databases from SQL and NoSQL are MySQL and MongoDB.

• MySQL is an open-source relational database management system that


works on many platforms.
• It provides multi-user access to support many storage engines and is
backed by Oracle.

The following are the features of MySQL:


• Ease of Management – The software very easily gets downloaded and also
uses an event scheduler to schedule the tasks automatically.
• Robust Transactional Support – Holds the ACID (Atomicity, Consistency,
Isolation, Durability) property, and also allows distributed multi-version
support.
• Comprehensive Application Development – MySQL has plugin libraries to
embed the database into any application. It also supports stored
procedures, triggers, functions, views and many more for application
development. You can refer to the RDS Tutorial, to understand Amazon’s
RDBMS.
• High Performance – Provides fast load utilities with distinct memory caches
and table index partitioning.
• Low Total Cost Of Ownership – This reduces licensing costs and hardware
expenditures.
• Open Source & 24 * 7 Support – This RDBMS can be used on any platform
and offers 24*7 support for open source and enterprise edition.
• Secure Data Protection – MySQL supports powerful mechanisms to ensure
that only authorized users have access to the databases.
• High Availability – MySQL can run high-speed master/slave replication
configurations and it offers cluster servers.
• Scalability & Flexibility – With MySQL you can run deeply embedded
applications and create data warehouses holding a humongous amount of
data.
What is MongoDB?
• MongoDB is a non-relational database which stores the data in documents.
• This type of database stores the related information together for quick
query processing.

The features of MongoDB are as follows:

• Indexing: It indexes are created in order to improve the search


performance.
• Replication: MongoDB distributes the data across different machines.
• Ad-hoc Queries: It supports ad-hoc queries by indexing the BSON
documents & using a unique query language.
• Schemaless: It is very flexible because of its schema-less database that is
written in C++.
• Sharding: MongoDB uses sharding to enable deployments with very large
data sets and high throughput operations.

MySQL vs MongoDB

Key Areas MySQL MongoDB


Uses Structured Query Uses MongoDB Query
Query Language
Language(SQL) Language
No restrictions on schema
Flexibility of Schema Pre-defined schema design
design
Does not support JOIN
Relationships Supports JOIN statements
statements
Uses privilege-security Uses role-based access
Security
based model control
Performance Slower than MongoDB Faster than MySQL
Provides excellent support Provides excellent support
Support
24*7 24*7
• Triggers & SSL
• Auto-sharding
Support
• Comprehensive
• Provides text
Key Features secondary indexes
searching and
• In-memory speed
indexing
• Native replication
• Query caching
• Integrated • Embedded data
replication support models support
• Different storage
engines with various

Supports Master-Slave Supports built-in replication,


Replication
Replication sharding, and auto-elections.
• Best fit for data with
tables and rows • Best fit for
• Works better for unstructured data
small datasets • Works better for large
• Frequent updates datasets
Usage • Strong dependency • High write loads
on multi-row • High availability in an
transactions unstable environment
• Modify large volume • Data is location-based
of records

The community of MySQL is


Has a good active
Active Community much better than that of
community.
MongoDB.

You might also like