Databases are an important part of an application, be it a simple form to a complex enterprise level to a mobile application we need our data to be stored. Now there are a lot of SQLs up for grab in the market, but which one to choose? How will a developer or an architect choose the best way to store their data?
What are the different types of database?
Databases provides way to store data into some space which will be secure and can easily be retrieved without any data loss. Now depending on their usage, databases can be of different types. Some of which are listed below:
- NoSQL
- Relational
- Object-oriented
- Centralized
- Distributed
- Cloud
- Network
- Hierarchical
In this blog, we will be discussing that are primarily used by the development teams i.e., Relational database and NoSQL database.
What is SQL?
SQL stands for Structured Query Language is used to access and manipulate data stored in database.
So what kind of database does it query? RDBMS i.e., Relational Database Management System forms the basis of SQL from which it retrieves data stored. Now when we talk about SQL vs NoSQL, basically we refer to RDBMS vs NoSQL because SQL is just a language to fetch data from RDBMS.
Data in RDBMS is stored in objects known as table that consists of rows and column. Each column has similar type of data stored into several rows. The tables have a well defined structure which is generally fixed while it is being created and rarely changed later.
The reason it has the word "Relation" is because we can relate a table with another table which might contain data that are linked with one another having some useful information. A table can be linked with another when at least one of their columns match, for example, both contains a column "ID" that have similar entries and when linked together might form a row with relevant information.
RDBMS follows ACID property where
A stands for Atomicity
C stands for Consistency
I stands for Isolation
D stands for Durability
Some examples of RDBMS are Oracle and SQL Server.
What is NoSQL?
NoSQL or non-relational databases stores data differently from that of relational databases. They don't have a fixed structure and non-tabular in nature. Due to their document-oriented or key-value structure, data is not stored together and not partitioned due to which read and write operations for a single entity is faster as compared to Relational database models when it comes to querying a non-complex data.
Although NoSQL follows some of the ACID properties, but it mostly follows BASE property where
B stands for Basically
A stands for Available
S stands for Soft State
E stands for Eventual consistency
Some examples of NoSQL are MongoDB and Couchbase.
How to decide which database to use?
RDBMS and NoSQL have very well defined separate uses and based on the type of application for which the data is to be stored, it can be decided which database to be used.
Let us take for example, School Management System where there will be data including students and teacher. A teacher can teach subjects in different classes and various types of such data which are linked to one another. Now if we chose NoSQL here, that won't be fast to fetch because if we want to get record of a teacher who manages three classes, we have to search through all the data to find the relevant information. On the other hand, with RDBMS this can be achieved just by using a simple query since there will be a relation between student and teacher table with a common (say ID) column.
Now sticking to the same application, let us consider Registration form for the students. There will be several fields such as multiple phone numbers, multiple address, might be parents and local guardian can be different and so on, it can go more than 50 columns or much more. Now here there is no fixed set of data that can be saved from the forms as the form can be dynamic. Now if we try to define a schema for such a table, it will be hard and might require frequent changes which is not all feasible. For this information, we can go for NoSQL which will be faster since one row per student no matter how many form fields are there and requires no schema to be defined.
Even for the Student Registration we define a fixed set of data to be asked for, multiple addresses and multiple phone numbers will either make the table with lot of columns or more rows per student which is not at all a good design to be used in a database.
Conclusion:
It is clear from the above explanations, if you have structured data and requirements are clear then RDBMS is the choice to go with especially since they follow ACID property. However if data is unstructured and requirements keep changing then NoSQL is the database to bet on.
With data growing day by day, it has become importance in today's concepts that the information needs to be fetched faster and since RDBMS joins are costly, many companies are inclining towards NoSQL databases. In most NoSQL databases, data is stored as key-value pair and although all the ACID properties are not met, it follows BASE property hence ensuring that the speed of data retrieval is fast enough to meet today's growing data demands.
Comments
Post a Comment