# Relational vs. Non-Relational Databases

## Relational vs. Non-Relational Databases

### Relational database&#x20;

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.

<figure><img src="/files/SgC2qtbchLqP9lzR9Xbp" alt=""><figcaption><p><em>Data is stored as tables with rows and columns in a relational database</em></p></figcaption></figure>

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

#### Advantages of relational databases <a href="#advantages-of-relational-databases" id="advantages-of-relational-databases"></a>

ACID compliance

Data accuracy

Normalisation&#x20;

#### Disadvantages of relational databases <a href="#disadvantages-of-relational-databases" id="disadvantages-of-relational-databases"></a>

Flexibility&#x20;

Scalability&#x20;

Performance

### Non-relational database

#### What is a non-relational database? <a href="#what-is-a-nonrelational-database" id="what-is-a-nonrelational-database"></a>

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&#x20;

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:

<figure><img src="/files/x08ToBIY8r8UddVCKB3B" alt=""><figcaption><p><em>How data is stored in a document non-relational database</em></p></figcaption></figure>

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

<figure><img src="/files/UzueXCHc1xKvnywST6c7" alt=""><figcaption></figcaption></figure>

### When to use a relational database <a href="#when-to-use-a-relational-database" id="when-to-use-a-relational-database"></a>

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

Normalisation is a must to keep the size of data low&#x20;

There is complex relationship between participating entities

You need to work with existing tool sets

### When to use a non-relational database <a href="#when-to-use-a-nonrelational-database" id="when-to-use-a-nonrelational-database"></a>

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

<figure><img src="/files/gqNtsJiv4wLnObK0IySq" alt=""><figcaption></figcaption></figure>

### Read more

{% embed url="<https://www.mongodb.com/compare/relational-vs-non-relational-databases>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://raviram.gitbook.io/cosmosdb/relational-vs.-non-relational-databases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
