Let’s have an example of Sql schema in which we have EmployeeId , FirstName, LastName, DepartmentName and DepartmentNam is a complicated object so the way I’m going to be storing it is in a seperate table . Now, the DepartmentName (Executive )corresponds to row which means that the complete DepartmentName is position(Head), Salary(30,000), State (Delhi). So,here you can see their is some sort of foreign key mapping and that’s how we store data in Sql.
Now come to NoSql:-
their is key-value system — -
EmployeeId(key) =1 and value =
— Here column name(FirstName) maps to a value (John) .
— DepartmentName is no longer a foreign key its just another object within this object .
— Here , if we have some null values we don’t even need to store them unneccessarily .
— We can add as many as columns according to our need because it does not depend on schema like Sql and remove columns as well .
In Sql ,whenever you are doing a new attribute addition , let say we have some new attribute added before Id which is Day for example, so when we actually add a new column to this Sql database it becomes very expensive operation, it’s also risky to maintain consistency at this time.
2. Insertion and retrievals are so easy :-
Like we know that Select* is so common nowadays unless it is highly required to get some specific data . So, if we need the whole data ,why not to store at one place.
In Sql ,you may need joins sometimes , to retrieve data from different tables , but here all your required data is contained in one block.So it’s little easier to insert and retrieve data from NoSql.
3. Built for scale :-
They are built for aggregations also .When a person is storing data in the NoSql database they usually expecting to be getting some important information out of that data for example what is the average age , total salary . these kind of databases are built of finding metrices and getting intelligent data.
Disadvantages : — — — -
- Not too many updates are supported inherently in this .The issue which arises is , In NoSql the data may not be consistent meaning that the two nodes may have different data for same Id ,while Sql database gives you ACID properties by which we can solve them.
- you can’t have transactions using NoSql , that’s the big reason that financial system don’t use NoSql databases for their transactions .
- Not read optimized , means if I ask to give me all the ages of all the employees that we have in the company what’s going to happen is it’s going to these blocks and each time it’s going to read the entire block then filter out the age and do that for every row then return the result. In Sql you just have to go to the column and then retrieve it , it’s also not that easy but more efficient than NoSql.
- Relations and joins are hard to apply.
Thanks for giving your valuable time.