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
idnamepricedescriptionquantity
1chair15somewhere to sit5
2book5something to read10
3pen2something to write15
  • 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

SQLNoSQL
SchemasNo Schema
RelationsNo or very few relations
Data is distributed across multiple tablesData is distributed along multiple collections
Horizontal scaling is difficult, while vertical scaling is easyBoth type of scaling works easily
Limitations for lots of reads and writes per secondNo 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.