SQL vs NoSQL
- SQL course
- Expert
- Lesson 34/45
- 5 min
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
-- NoSQL query
SELECTSample solution
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
SELECT data____'name' FROM documents
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.