d-_-b
d-_-b

Reputation: 883

Explain Like I'm Five : SQL (relational) and NOSQL (non-relational) databases

If I had to explain SQL & NOSQL to a college student within 1 minute :


You're familiar with an Excel spreadsheet, right ? That is SQL:

id, name, age, weight
1, Adam, 20, 150
2, Bob, 30, 160
...

Now imagine if you didn't know the column names up-front, and wanted to flexible in adding new ones later. That is NOSQL :

id, column, value
1, name, Adam
1, age, 20
1, weight, 150
2, name, Bob
2, age, 30,
2, weight, 160
2, gender, Male
...

In technical jargon - they are PIVOTs of each other.

For a query like :

select * from people where age > 20

SQL will generally run a single server, with all data in one database, and use an index on age column to filter data.

NOSQL will generally run in a cluster in parallel, with data spread across multiple servers, where each one filters its local age data (MAP), and then a central server combines results (REDUCE)


Is that a good high-level explanation ?

Upvotes: 1

Views: 582

Answers (1)

Stefan Dzalev
Stefan Dzalev

Reputation: 283

If I had to explain this topic like you're five it'd go something like this: I'd sit you on the table and get a shape sorter toy.

  • SQL: The toy has ALREADY DEFINED shape holes where ONLY the specific shapes can go through and enter. This also means that only the shapes that fit through the shape holes can be inserted, so we can be sure that only the shapes we think should be inserted are inserted. When we want to get the shapes out we have to get them out through the same holes, which can be a bit more work. In SQL the tables are already defined and only data that is aligned with the table definition can be inserted and in SQL we are likely to do a lot of joins between tables to get the result we want which can require more time and performance.

Then I'd get rid of the surface with the shape holes so that it would be just a plastic box with a large opening (the plastic with the shape holes is gone).

  • NoSQL the toy doesn't have a surface with holes that the shapes have to fit to go through, but has a large opening instead. This means that you can put everything in without care whether it is aligned with some ALREADY DEFINED shape. This means that we can put whatever we want inside, because there are no ALREADY DEFINED shapes that can only be inserted. Also, when we want to get all of the shapes out we can just turn the box upside down and all of the shapes will fall out. In NoSQL databases we do not follow definitions when we insert data and we don't do joins so not as much time and performance is required.

Upvotes: 2

Related Questions