Relational vs non-relational databases

Both relational and non-relational databases represent rather wide variety of possibilities and implementations but I’ll focus on the main differences between the two. First of all, it is about how data is managed. In relational databases you can use SQL, that is simple and lightweight language for writing database scripts. Non-relational databases do not support it, so you might refer to them as NoSQL databases.

The second big difference is structure how data are stored. In relational databases data are divided into tables, that may have relations between them. With the support of primary keys, triggers and functions you are capable creating complex dependencies between tables. This most likely will represent business model and logic inside of the database. NoSQL databases are based on the very simple structures like key-value storage or a graph, that does not support such relations.

Image from: https://codewave.com/insights/nagesh-on-when-to-use-mongodb-and-why/

Short summary

Knowing that upfront lets have a short summary of the two:

 SQLNoSQL
TypeRelational databaseNon-relational database
StructureStrict schema, data is stores in tablesSchemaless, data is kept in key-value pairs, columns, documents or graphs
Getting dataStructured Query Language with vast options for joining and querying dataUnstructured, simple language that supports any kind of schema
Consistency and availabilityConsistency is enforced and prioritized over availability and performance, supports ACID transactionsPerformance can be prioritized over consistency and availability, transactions are not always supported
ScalabilityVertical - you can scale by adding more power to an existing machineHorizontal - you can scale be adding more machines
UsageStructured data where enforced dependencies corresponds to application business logic. Great for data, where schema don't change oftenGreat for modern web application for storing session information, user profiles or shopping carts.
ExamplesOracle, MySQL, MSSQL, IBM DB2, PostgreSQLMongo DB, Couch DB, Raven DB, Redis, Neo4j

What should I use?

If you’re starting with a new project and you’re wondering what to use, it’s a good opportunity to consider using NoSQL database. I would especially encourage you to try it for small and pet projects, because the best known like MongoDB and Couchbase works as SaaS. NoSQL is also relevant for big projects because it offers great scaling and is very easy to set up. On the other hand, non-relational databases may seem too simple or even limited, because of lack of triggers, stored procedures and joins. It may also be a threat to use another data management system, because it brings overhead for the team, to get accustomed to it. However, I strongly recommend trying it.

If you’re interested in NoSQL databases, check out my post about document storage – Azure Cosmos DB: Getting started with CosmosDB in Azure with .NET Core

Leave a Reply

Your email address will not be published. Required fields are marked *