What is “No” in NoSQL ?

What is “No” in NoSQL ?

We keep hearing about NoSQL these days. Many of us might think what’s the big deal if there is no “SQL”. Some of us might think OMG, there is no SQL ? How the hell the things are going to work, if there is no SQL? So, Let’s try to understand what does it mean when we say, NoSQL Database. The easiest way to confirm is Yes, there is no SQL if you use these databases. Yet, there is no need to worry too much about it. Perhaps SQL has it’s own limitations, though it has many advantages and ruling the industry for many years. The first and foremost of all is Relationship. For Eg; If you want to store company data like company name, address, departments, employees etc. You could already identify the entities and their relationships like one-one, one-many, many-one etc. If you want to aggregate the data? is there any way? Yes, there are joins, unions etc. So, lets try to fetch the data for the below page and see how many tables will be involved when we have to fetch the data for this page.

SQL-Relationships
Fig: 1

In Figure 1, we have seen the number of relationships you need to just define a structure of a company. If the same thing we have to do with a NoSQL format, how would it look like ? I mean the non relational databases.


{
'Company':'XYZ Company',
'Departments':[
'Dept1':
{ 'Name': 'HR',
'Employees':[ {'Name':'A','address':'City A', 'Sport': 'Tennis' },{'Name':'B','address':'City B', 'Sport': 'Cricket' } ]},
'Dept2':
{ 'Name': 'Admin',
'Employees':[ {'Name':'X','address':'City X', 'Phone':12121 },{'Name':'Z','address':'City Z', 'Phone':232323 } ]},
'Dept3':
{ 'Name': 'IT',
'Employees':[ {'Name':'N','address':'City N' },{'Name':'M','address':'City M' } ]}
],
'Addressg':'#55, 10 Avenue, ABC City, US'
}

This is what is called as Aggregation in NoSQL world. This structure would give you a flexibility of retrieving all the details of the company together and fast, instead of storing the data in different tables and different columns. This difference leads to many other differences between these two worlds.

If you closely observe the above JSON object, each employee object is having different attributes For Eg: HR department has  sport, Admin depart has Phone and IT department has non of these attributes. So, this is possible because these databases are scheme less. Each employee and each document might contain completely different format. This could be advantage as well as problem. Usually this is considered as advantages for NoSQL databases because we don’t need to define Schema before hand and this would give the flexibility to add new fields whenever we want in future to the same document.

References:

The Book – No SQL Distilled by Pramod and Martin Fowler would give you a very good understanding of NoSQL.

Blogs you would like to follow – nosql.mypopescu , NoSQL Weekly

Happy Reading 🙂