Database Management System, Which one you choose? (ft. SQL vs. NoSQL)
My initial foray into Database Management Systems (DBMS) began with MongoDB, a document-oriented program. As a NoSQL(Not Only SQL) database, MongoDB operates with JSON-like documents that may use optional schemas, making it remarkably user-friendly for those unfamiliar with coding, once you grasp a few fundamental queries like '$and', '$or', '$ne', '$nor'.
As I became more used to managing data and its schema while developing applications, my curiosity about database structures deepened, particularly about how they function in “relational” environments. This curiosity led me to explore SQL(Structured Query Language), which contrasts with NoSQL in its approach, focusing on storing and processing information in relational databases.
SQL has been in use since the 1970s, benefiting from a long timeline of development, whereas NoSQL only emerged in the 1990s. Although I initially started learning about DBMS through the NoSQL tool MongoDB, I found it essential to understand SQL first. This foundational knowledge is crucial before delving deeper into the broader database management systems landscape, encompassing both NoSQL and SQL technologies.
Relational Database Management Systems (RDBMS) are the most prevalent type of database management systems (DBMS) in use today. As the term 'relational' suggests, these systems are based on organizing data into tables, which can relate to one another through common data attributes. For example, a simple table might look like this:
In SQL, the language used to interact with RDBMS, you might use the CREATE TABLE command to define a new table. Here’s how you could create the table shown above using SQL:
What sets apart SQL from NoSQL?
Here are a few distinctive differences you can easily notice.
1. Structure
The way they store the date differ.
For example, in SQL, you store information following the fixed Schema.
This is the same table I introduced earlier. If you want to add email address to this table, you can’t because in SQL, everyone has to follow a strict Schema(data storage structure). That is, you can’t store data that does not fit this Schema. Therefore, it is impossible to add an email (there is no email column).
In contrast, NoSQL allows you to add data with different structures. For instance, adding an email key-value to "Chat Faker" document (equivalent to a record in SQL) does not impact other documents. Therefore, NoSQL does not require data structures to be uniform.
2. Relationship
SQL makes it easy to specify relationships between data.
For example, by looking at an Orders table, you can tell that Faker bought 12 pens through the Customer ID and Product ID. SQL allows you to access tables through these defined relationships between each table, thereby handling the relevant data without duplication.
In contrast, NoSQL typically stores all related data in one collection (similar to a table in SQL). For example, when Chat buys 12 pens, the Orders collection would include the order number, customer information, and product information all together. Unlike SQL, which stores only IDs, NoSQL saves comprehensive details like the customer's name and age. This allows us to obtain all the necessary data from just the Orders collection, without needing to refer to Customers or Products.
Recommended by LinkedIn
This approach results in duplicated data, unlike SQL, which means you must be careful whenever updating data. For example, if you add Chat’s age to the Customer collection but fail to update it in the Orders collection, this can lead to inconsistencies.
3. Scalability
SQL typically only supports vertical scaling. Vertical scaling refers to enhancing the server's performance by upgrading or adding hardware.
In contrast, NoSQL supports horizontal scaling. This allows for the distribution of the database across additional servers as they are added.
Which one is better; SQL Vs. NoSQL
NoSQL databases are indeed known for their flexible data models, which can make them more accessible for managing diverse and unstructured data. On top of this, if you use GUI(graphical user interface) tool with NoSQL databases, such as MongoDB Compass or Studio 3T, can potentially simplify many tasks further, making the technology even easier to use.
On the other hand, SQL databases are renowned for their structured data management, offering strong data consistency and complex querying capabilities, which are ideal for intricate data analysis. Also, they adhere to ACID(Atomicity, Consistency, Isolation, Durability) compliance, ensuring reliable transaction processing essential for applications such as financial and booking systems.
My Conclusion
As a beginner learning about database management systems and having experienced both SQL and NoSQL, I've noticed each has distinct advantages and disadvantages.
I particularly like the rigorous control over data structures that SQL offers, as well as the ability to write complex queries and manipulate data through different functions such as joins, subqueries, and aggregate functions.
On the other hand, NoSQL excels in scalability, especially for horizontal scaling, which involves adding more servers to manage increased load effectively. NoSQL also allows for flexibility in structuring data, with various models like document, key-value, and columnar stores, giving me greater control over data structure and access.
What’s clear is that proficiency in both SQL and NoSQL significantly enhances my ability to manage databases and optimize data performance, providing the flexibility needed to handle complex datasets and extract the desired information efficiently. I believe that this dual expertise is invaluable in the diverse and evolving landscape of database technology.
Which one do you prefer? Are you SQL person or NoSQL person? ;-)
Source:
(This is a book I recently enjoyed to learn about basic DBMS & SQL(mostly MySQL) - The original version is in Japanese and I bought the Korean version but I don’t thinks there is English version unfortunately.)
Tech Support | Full Stack Dev Experience | Passion for Helping People with Tech
1yVery interesting take on SQL and NoSQL database. Reminds me of the conversation we had in bootcamp with Omar. Inspiring as always!