Open Questions: SQL or NoSQL as Your First Database?

"Should I learn SQL or NoSQL first?" is one of the most common questions from new developers. The honest answer is that both are useful, but they teach different things. This page sets out the arguments without declaring a winner for everyone.

What the words mean

SQL databases (also called relational databases) store data in tables with fixed columns. You query them with SQL. Examples: SQLite, PostgreSQL, MySQL.

NoSQL is a broad label for databases that do not use the table model, or not only. The most common type beginners meet is a document database, which stores records as JSON-like documents. MongoDB is a well-known example.

-- SQL: a row in a table
INSERT INTO books (title, year) VALUES ('Example Book', 2020);
// Document database: a document in a collection
db.books.insertOne({ title: "Example Book", year: 2020, tags: ["fiction"] });

Arguments for starting with SQL

  1. Concepts that last. Tables, keys, relationships and constraints appear everywhere in computing, even in NoSQL design.
  2. Very widely used. A huge number of apps, reports and jobs use SQL.
  3. The database protects your data. Rules such as NOT NULL and foreign keys stop many mistakes.
  4. Easy to start. SQLite needs no server at all.

Arguments for starting with a document database

  1. Feels familiar to JavaScript developers. Documents look like the objects you already use.
  2. Flexible shape. You can add a new field without changing a schema first.
  3. Quick for some projects. If your app always reads and writes whole objects, documents can map neatly.

Open questions

These are the points where thoughtful people disagree:

Comparing them for a first project

QuestionSQL (relational)Document database
Setup for learningVery easy with SQLiteEasy with a local server or hosted free tier
StructureDefined up frontFlexible per document
Linking related dataJOINsEmbedding or references
Protection from bad dataStrong, through constraintsDepends on your code and optional validation
Transfer to other databasesHighMedium

A suggested approach

If you have no strong reason to choose otherwise, start with SQL. It gives you a solid foundation, and learning a document database afterwards will be easier because you will understand what you are gaining and giving up. If your course, club or job uses a document database, start there, but spend some time with SQL too.

Our plain guide to relational and NoSQL databases goes into more detail with examples.

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.

This is a static page of sample discussion topics. There is no live forum, membership or user community on this site.