A Plain Guide to Relational and NoSQL Databases

Summary: relational databases store data in tables linked by keys and are queried with SQL. "NoSQL" is an umbrella name for databases that store data in other shapes, such as documents or key-value pairs. Both are useful; for a first database-backed app, a relational database is a gentle and widely used starting point.

In short: tables and SQL for most first apps; other shapes when your data or scale clearly fits them. Learning SQL first makes every other kind easier to understand.

Relational databases

A relational database keeps data in tables with fixed columns. Rows in different tables are linked with keys. You ask questions in SQL. PostgreSQL, MySQL, MariaDB, SQLite and SQL Server are relational.

SELECT customers.name, orders.item
FROM orders JOIN customers ON customers.id = orders.customer_id;

Good at: data with clear structure and relationships (customers, orders, products), enforcing rules such as "every order needs a customer", and answering new questions you did not plan for when you designed the tables.

NoSQL databases

"NoSQL" does not mean one thing. It covers several families:

FamilyStores data asWell-known examplesOften used for
DocumentJSON-like documentsMongoDB, CouchDBRecords whose fields vary a lot
Key-valueA value looked up by a keyRedisCaches, sessions, counters
Wide-columnRows with flexible columns spread over many machinesApache CassandraVery large, write-heavy data
GraphNodes and connections between themNeo4jNetworks of relationships, such as social links

A document might look like this:

{ "name": "Ana", "orders": [ { "item": "Lamp" }, { "item": "Rug" } ] }

Here a customer and their orders live together in one document instead of two tables.

How they differ, simply

Structure. Relational tables have a fixed set of columns declared up front. Document databases let each document have different fields, which is flexible but means your code must cope with the variety.

Relationships. Relational databases join tables easily. Many NoSQL databases expect you to store related data together, or to fetch it in separate steps.

Rules. Relational databases enforce keys and constraints for you. In many NoSQL databases more of that checking happens in your application code.

Query language. SQL is shared, with small differences, across relational databases. NoSQL databases each have their own query style.

The lines are blurring

Modern relational databases can store and query JSON (PostgreSQL's jsonb type is a popular example), and some NoSQL databases have added SQL-like query languages and stronger rules. Choosing is less of an all-or-nothing decision than it used to be.

Which should a beginner learn first?

For most people, a relational database and SQL. Reasons:

  1. SQL skills transfer between many databases and jobs.
  2. Learning to design tables and keys teaches you to think clearly about data, which helps with any database.
  3. SQLite lets you practise with no setup at all.

Later, try a key-value store like Redis for caching, or a document database for a project where its shape fits. You will understand their trade-offs much better once you know what tables and joins give you.

Next steps

Start with how to create your first SQLite database and table.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.

Related pages on this site