Relational vs. Non-Relational Databases

Relational vs. Non-Relational Databases

Relational database

A relational database, or relational database management system (RDMS), stores information in tables. Often, these tables have shared information between them, causing a relationship to form between tables. This is where a relational database gets its name from.

Data is stored as tables with rows and columns in a relational database

The details of the product are in a separate product table. This makes information organized and more structured.

Advantages of relational databases

ACID compliance

Data accuracy

Normalisation

Disadvantages of relational databases

Flexibility

Scalability

Performance

Non-relational database

What is a non-relational database?

A non-relational database, sometimes called NoSQL (Not Only SQL), is any kind of database that doesn’t use the tables, fields, and columns structured data concept from relational databases. Non-relational databases have been designed with the cloud in mind, making them great at horizontal scaling.

There are a few different groups of database types that store the data in different ways:

Document databases

Key-value databases

Graph databases

Wide-column databases

Document databases store data in documents, which are usually JSON-like structures that support a variety of data types. These types include strings; numbers like int, float, and long; dates; objects; arrays; and even nested documents. The data is stored in pairs, similar to key/value pairs.

Consider the same customer example as above. In this case, however, we are able to view all the data of one customer in a single place as a single document:

How data is stored in a document non-relational database

Due to documents being JSON-like, they are much easier to read and understand for a user. The data is organized, and also easy to view. There is no need to reference multiple documents or collections to view data of a single customer. The documents map nicely to objects in code in object-oriented programming languages, making it much easier to work with.

How do they compare

When to use a relational database

Data is predictable in terms of structure size and frequency of access

Normalisation is a must to keep the size of data low

There is complex relationship between participating entities

You need to work with existing tool sets

When to use a non-relational database

Data keeps varying in terms of their structure and size

Your application is distributed across multiple nodes on a cloud

Where we need low latency and eventual consistency

Summary

Read more

Last updated