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.
Knowing that upfront lets have a short summary of the two:
|Type||Relational database||Non-relational database|
|Structure||Strict schema, data is stores in tables||Schemaless, data is kept in key-value pairs, columns, documents or graphs|
|Getting data||Structured Query Language with vast options for joining and querying data||Unstructured, simple language that supports any kind of schema|
|Consistency and availability||Consistency is enforced and prioritized over availability and performance, supports ACID transactions||Performance can be prioritized over consistency and availability, transactions are not always supported|
|Scalability||Vertical - you can scale by adding more power to an existing machine||Horizontal - you can scale be adding more machines|
|Usage||Structured data where enforced dependencies corresponds to application business logic. Great for data, where schema don't change often||Great for modern web application for storing session information, user profiles or shopping carts.|
|Examples||Oracle, MySQL, MSSQL, IBM DB2, PostgreSQL||Mongo 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