In this tutorial, we are going to discuss differences between SQL and NoSQL at the same time we are going to see the reasons which will help you to select best out of them.
Let's first discuss the Relational Database. We know that in Relational Database things are stored in tables and it came out in 1970s from IBM and then Oracle took it on and really made it a thing. Common databases that are relational are obviously Oracle, MySQL, and Postgres which is an open-source version which is similar to MySQL.
Now let's discuss NoSQL. NoSQL started mostly in early 2000 that's one of the improvements. Mostly Google, FaceBook, Amazon etc. have a huge amount of data to handle therefore thought there may be a different way to do it. So started creating different formats for databases. Thus You have different databases like Key-Value databases, Column Family Databases, Graph Databases and Document Databases.
Key-Value Databases: - Which essentially have a key which you can hash and find your value. For Ex: - There are common databases which are used by Reddit, Amazon SimpleDB etc.
Column Family Databases:- It is also similar to Key-Value databases, in which you are hashing keys to values but instead of hashing keys to single values the keys are hashed to a whole family of columns. Common Column Family Databases are Cassandra etc.
Document Databases: - Which we use in MongoDB. In which whatever you want to put into, you can add it into Document and embed it. You can embed more documents. Basically whatever you want to embed into it, go down as far as you want into a rabbit hole. CouchDB is a common document database.
Graph Databases:- These are more commonly used for really big complex data in which you have a node that can have properties on it and then you have edges that connect to those nodes. The Graph Databases have their own special languages but not many people use them, but they are really good.
Let's see Why so many people like RDBMS's:-
The Big advantages of using RDBMS's are:-
1. Structure:- It is easy to join the table and search for any information through it as these are organized.
It helps in Error checking, enforces relationships. You end up with reduced duplications, Only update in one place.
2. Fast Joins:- Cross-indexed index stores where foreign id's object is in the other table. It is a query optimizer. It supports documentations, Stack overflows. It is stable and also helps in Reporting and analysis across relations.
SQL Databases and NoSQL databases do ACID Compliance.
- Atomicity:- it is all or nothing i.e. the idea is to do all the transactions or nothing. If any error occurs in between then you will have to reverse or repeat the process.
- Consistency: - All the data written to databases must be valid like Foreign Keys, Data types, Unique, Not Null. Databases should have a unique name.
- Isolation:- Stops collision between multiple changes to the same document.
- Durability:- Once executed, data is immediately saved to disc.
- Transactions let you make complex, multistep actions.
- It provides either all consistency or nothing.
Why people started looking for new ways when they have been using RDBMS's for such a long time?
Because: - They need more speed and large data sets and unstructured data needs to be handled. Large data like - Google, Facebook, Amazon etc.
Benefit's of NoSQL:-
1. Flexibility: - It is flexible enough to store non-structured data. It is easy to change the fields.
2. Easy to use: - It is easy to use and get running.
3. Web-scale:- Non-relational makes easy distributions and fast queries.
4. No Normalization is required, only JSON - Format when you don't have one document with a bunch of nested data. We have all done a lot of relational data with MongoDB it's possible.
5. The Relations are slow and can get messy.
6. Not ACID Compliant
7. Data is less secure against errors and loss and also the data is not immediately persisted.