Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 13: NoSQL and SQL

This chapter looks at how NoSQL and SQL databases differ and how SQL can be used alongside NoSQL databases.

Differences between NoSQL and SQL

NoSQL (Not Only SQL) databases and SQL databases take different approaches to storing and managing data. Knowing how they differ helps you choose the right database for your application’s requirements.

Characteristics of NoSQL databases

  • Flexible schema: NoSQL databases often have no schema or a flexible one, so developers can store and retrieve data without defining a schema first.
  • Scalability: NoSQL databases are designed to scale horizontally, which makes them suitable for large volumes of data spread across distributed systems.
  • Non-relational: NoSQL databases usually don’t store data in tables with fixed relationships between them. They use document, key-value, columnar, or graph-based data models instead.

Characteristics of SQL databases

  • Structured Query Language (SQL): SQL databases define and manipulate data with SQL, a standardized query language, which makes relational data models easy to work with.
  • ACID transactions: SQL databases support ACID (Atomicity, Consistency, Isolation, Durability) transactions, which protect data integrity and reliability.
  • Relational model: SQL databases follow a relational model of tables with predefined schemas and relationships between them.

Using SQL with NoSQL databases

NoSQL databases have benefits of their own, but in some situations SQL can complement them and add functionality and flexibility.

Integration via SQL interfaces

Some NoSQL databases provide SQL interfaces or compatibility layers that let developers work with the database using SQL-like syntax. These interfaces bridge the gap between SQL and NoSQL, so you can use the SQL skills and tools you already have with a NoSQL database.

Data aggregation and analysis

SQL can handle data aggregation, analysis, and reporting even when the data is stored in a NoSQL database. Developers can export the data into SQL-compatible formats or use SQL-on-Hadoop solutions, then run complex analytical queries on it and draw insights from it.

Hybrid architectures

A hybrid architecture uses SQL and NoSQL databases together to get the strengths of each. For example, SQL databases may handle transactional data storage and relational querying, while NoSQL databases handle unstructured or semi-structured data and provide horizontal scalability.

Whether you choose NoSQL, SQL, or a hybrid approach, the right database technology depends on factors such as data structure, query requirements, scalability, and performance goals.