SQL vs NoSQL: Choosing a database for your next project
SQL is a query language used for managing data in a relational database system. It is key to roles like data scientist, software engineer, and data engineer. This path will teach you essential SQL queries, including SELECT, WHERE, DISTINCT, GROUP BY, and ORDER BY, along with advanced concepts like joins, subqueries, and aggregate functions. By mastering these skills, you’ll be prepared for the software industry with a strong foundation in SQL.
Overview of SQL and NoSQL databases #
In this section, we’ll provide a quick overview of both SQL and NoSQL databases. Furthermore, we’ll briefly discuss their architectures and provide a few examples of each type of database.
SQL databases #
SQL (structured query language) databases are essentially relational databases, meaning that data is organized in terms of their relationships with other data. Nowadays, relational databases are loosely referred to as SQL databases because SQL is the primary language used to create and manipulate data in relational databases. Relational databases were inspired by the rules of formal mathematics, specifically set theory. Set theory is a branch of mathematics that studies the properties of well-defined collections of distinct elements, called sets, and the relations between them.
So, in any relational database, you’ll find that data is organized into tables. Each table is made up of rows and columns. To identify a table’s row uniquely, we use a primary key. To establish relationships between different tables, we use foreign keys.
For example, if you’re tracking customers and orders in a SQL database, you can use a foreign key to link each customer to their respective orders. This would allow you to answer questions like “How many orders did Customer X place?” or “What was the total value of all the orders placed by Customer Y?”
Note: Relational databases are managed using a relational database management system, or RDBMS. MySQL, MariaDB, and SQLite are all examples of open-source RDBMS. Oracle Database is an example of a multi-model database management system, which supports relational databases in addition to other data models.
NoSQL databases #
NoSQL (not only SQL) databases, on the other hand, are non-relational. There are several types of NoSQL databases, such as column-oriented, graph-based, document-oriented, and key-value store databases. The focus of this article will be on document-oriented databases as they are one of the most widely used NoSQL databases. Document-oriented means that data is organized into documents, which can contain any kind of information. A document stores data in field-value pairs, where fields can be of different types. All the information about an object is stored in a single document, whereas documents containing similar objects are placed in a collection. Instead of SQL, a document-oriented database uses simple API or a query-based language to create and manipulate documents. Examples of document-oriented databases are DocumentDB, MongoDB, and OrientDB.
It’s worth noting that there are different types of NoSQL databases, each with its own strengths and weaknesses. The most popular type is the document database, which is what we’ll be focusing on in this article. Other types include key-value stores, column-oriented databases, and graph databases.