# SQL vs. NoSQL

SQL and NoSQL - or relational databases and non-relational databases.

## SQL

Relational databases are structured and have predefined schemas.

Relational databases store data in rows and columns.

## NoSQL

Non-relational databases are unstructured, distributed and have a dynamic schema

### Most common types of NoSQL

**Key-Value Stores**: Data is stored in an array of key-value pairs.

e.g. Redis, Voldemort and Dynamo

**Document Databases**: In these databases data is stored in documents

e.g. CouchDB, MongoDB

**Wide-Column Databases**: Instead of ‘tables,’ in columnar databases we have column families, which are containers for rows. (Unlike relational databases, we don’t need to know all the columns up front, and each row doesn’t have to have the same number of columns.)

e.g. Cassandra and HBase.

**Graph Databases**: These databases are used to store data whose relations are best represented in a graph.

e.g. Neo4J and InfiniteGraph

## High Level Differences between SQL and NoSQL

**Storage**\
SQL - stores data in tables\
NoSQL - different data storage models, such as KV-store, document, graph, columnar

**Schema**\
SQL - fixed schema, column must be decided; alter schema involves modifying the whole database\
NoSQL - schemas are dynamic

**Querying**\
SQL - SQL (structured query language)\
NoSQL - Unstructured query language, different databases, different syntax

**Scalability**\
SQL - most commonly, vertically scalable (increasing horsepower of hardware); harder to scale Relational DB across multiple servers\
NoSQL - horizontally scalable; adding more servers; many NoSQL DB also distribute data automatically

**Reliability or ACID Compliancy (Atomicity, Consistency, Isolation, Durability)**

SQL - vast majority of relational databases are ACID compliant\
NoSQL - most NoSQL solutions sacrifice ACID compliance for performance and scalability

## Which one to use?

### Reasons to use SQL database

* We need to ensure ACID compliance.
* Your data is structured and unchanging.

e.g. e-commerce and financial applications

### Reasons to use NoSQL database

* Storing large volumes of data that often have little to no structure.&#x20;
* Making the most of cloud computing and storage.&#x20;
* Rapid development.
