CodeBlanks Logo Icon CodeBlanks

SQL vs NoSQL

Compare SQL and NoSQL.

NoSQL comparison

NoSQL covers non-relational databases: document, key-value, column-family, graph. SQL demands a strict structure; NoSQL offers a flexible one. The CAP theorem limits you to two of three guarantees.

SELECT data->>'name' FROM documents
WHERE data->>'status' = 'active';

NoSQL offers flexible structure.

data->>'name' is selected from documents. WHERE keeps only the rows where data->>'status' = 'active' holds.

NoSQL comparison — details

CAP: consistency, availability, partition tolerance. During a network partition you pick two. SQL picks consistency + partition tolerance; most NoSQL picks availability + partition tolerance.

Practice NoSQL comparison

Select data->>'name' from the documents table; return only active documents.

Starter code

query.sql
-- NoSQL query
SELECT

Sample solution

query.sql
SELECT data->>'name' FROM documents WHERE data->>'status' = 'active';

Expected output

name
Ayşe
Mehmet

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Document access

Question
SELECT data____'name' FROM documents
Answer
SELECT data->>'name' FROM documents

Explanation: ->> returns a JSON field as text, while -> returns it as JSON.

2 SQL vs NoSQL: match the terms

Term Meaning
NoSQL non-relational
document document
CAP three guarantees
key-value key-value

3 How many guarantees does CAP limit?

  • Both of them
  • All of them
  • Only one of them
  • Two of the three Correct answer

Explanation: CAP limits you to two of three guarantees.

All lessons in Expert