SQL vs NoSQL

In this article, we will discuss the differences between SQL and NoSQL databases and when to use each.


SQL Databases

SQL databases are relational databases. These databases store data in relational tables, with rows and columns. Each row is uniquely identified by a primary key, such as Customer ID. Relationships between tables are defined by a foreign key. 

NoSQL Databases

NoSQL databases are databases that do not store data in relational tables. Depending on which NoSQL database you decide to use, the data may be stored by means of key-value pairs, documents, columns, or graphs


Key-Value Database

In a key-value database, data is stored in a hash table. Each individual piece of data has a unique key. This is especially helpful for storing data that does not contain a specific structure or schema.


Document Database

In a document database, data is stored as documents, most commonly in JSON or XML format. This facilitates the storage of unstructured data since these formats support embedded fields. 


Columnar Database 

In a columnar database, data is grouped in columns rather than rows. It is flexible in the sense that each column can have a different number of rows. Since the data is already stored in columns, columnar databases enable faster performance for aggregation operations.


Graph Database

In a graph database, each piece of data is stored as a node. The graph also contains edges, which define relationships between nodes. This database model is fitting for very large sets of unstructured data, such as social networks.


Summary

SQL databases are the appropriate choice when the data is structured in relational tables, when performing relational queries, and when enforcing constraints. When there is a need for high performance and minimal delay, particularly when dealing with unstructured, large amounts of data, NoSQL databases are the best option.

Examples

SQL Databases:

  • MySQL
  • SQL Server
  • Oracle
  • Db2

NoSQL Databases:

  • DynamoDB (Key-Value)
  • MongoDB (Document)
  • Cassandra (Column)
  • Neo4j (Graph)