A relational database stores records in tables with a fixed schema and links them with foreign keys. A non-relational database, often called NoSQL, stores data as documents, key-value pairs, wide columns, or graphs, and usually does not require a rigid schema up front. The choice of model affects how fast a project can grow and which queries stay fast as the data volume increases.
How the relational model differs from the document model
In a relational database, data is split into tables, each row has a predictable set of columns, and relationships between tables are described with foreign keys. This works well when data is well structured and the integrity of relationships matters: an order always references an existing customer, a payment always references an existing order. A non-relational database stores related data as a single document or record without splitting it into tables, and tolerates changes to the data structure on the fly more easily.
- a relational database checks the integrity of relationships at the DBMS level, not only in application code
- a document database stores nested structures as one piece, without extra table joins
- both models support replication and backups, the difference is in storage design, not reliability
A step-by-step setup of a relational DBMS on your own server is covered in the article setting up MariaDB on a VDS.
Comparing them by practical parameters
For a specific project the difference shows up most in three things: how strictly the data structure is enforced, how complex lookups are performed, and how the database grows as load increases.
| Parameter | Relational DB | Non-relational DB |
|---|---|---|
| Data schema | defined in advance, changed by a migration | flexible, documents can have different fields |
| Relationships between data | foreign keys, checked by the DBMS | stored inside the document or checked in code |
| Query language | SQL, one standard with dialects | its own API or query language per DBMS |
| Default port | 3306 for MySQL and MariaDB, 5432 for PostgreSQL | depends on the specific DBMS |
Setting up an alternative relational DBMS with a different set of features is covered in the article setting up PostgreSQL on a VDS.
What a typical query looks like
The difference in queries is clear in a simple example: getting a list of orders together with the customer's name. In a relational database this is a join of two tables on a foreign key.
SELECT orders.id, customers.name
FROM orders
JOIN customers ON customers.id = orders.customer_id;
In a document database the same result is more often obtained without a join: customer data is either already stored inside the order document, or fetched with a separate lookup by id. This is faster for simple reads, but makes it harder to update a customer's data across all of their orders at once.
When the relational model is justified, and when it is not
A relational database fits when data is well structured in advance and strict relationships between entities matter: billing, order tracking, accounting. Schema migrations stay manageable because the structure changes rarely and predictably.
A non-relational database is justified when the data structure changes often, the record volume grows faster than a single server can keep up with, or when disparate documents need to be stored without a shared schema. Moving data between different DBMS engines when switching storage models is covered in the article migrating a database.
What to do when choosing a data model
The decision should be based on the project's data, not on which technology is trending.
- write down the project's main entities and the relationships between them
- check whether strict relationship integrity needs to be enforced at the database level
- estimate the expected data volume and the nature of queries — point lookups or complex joins
- pick a relational DBMS for strictly structured data with frequent joins, and a non-relational one for disparate documents
The decision does not have to be the only one for the whole project: part of the data can live in a relational database, and another part nearby, in a non-relational store for a specific task.
Frequently asked questions
Can a relational and a non-relational database be used in the same project?
Yes, this approach is called polyglot persistence: the main entities live in a relational database, while data with a variable structure or heavy read load sits in a non-relational store next to it.
Which database is faster — relational or non-relational?
Speed depends on the nature of the queries, not the type of database: a point lookup by id is usually fast in both models, while joining several tables is faster in a relational DBMS.
Do you need to know SQL to work with a non-relational database?
No, most non-relational DBMS engines have their own language or query API, but understanding the relational model helps you grasp faster how data relates to itself in any database.