SQL Vs NoSQL
SQL (Structured Query Language)
- Examples are like MySQL, Postgres, etc
- Works with tables (storage container)
- We have a clear schema or fields that can go in the given table
- Lets take a product table
id | name | price | description | quantity |
---|---|---|---|---|
1 | chair | 15 | somewhere to sit | 5 |
2 | book | 5 | something to read | 10 |
3 | pen | 2 | something to write | 15 |
- We can't have things other than the schema that defined
- We can have more than one tables that are connected with each other
Two major properties
- relational
- strict schema
Relation could be
- one-to-one
- *one to many
- many-to many
NoSQL
- It can store lots and lots of data
- We have collections instead of tables
- Each collection has documents instead of rows
Major Properties
- No same schema
- Very flexible
- Keep adding new fields
- NO RELATIONS
- Superfast data querying
Comparison
SQL | NoSQL |
---|---|
Schemas | No Schema |
Relations | No or very few relations |
Data is distributed across multiple tables | Data is distributed along multiple collections |
Horizontal scaling is difficult, while vertical scaling is easy | Both type of scaling works easily |
Limitations for lots of reads and writes per second | No such limitation and fast searching can take place |
So what to use?
Any works with any application. NoSQL works when there's a lot to read. However incase of easy queries we can use SQL.