Difference Between SQL and NoSQL: SQL vs NoSQL

Tre'von Mitchell
4 min readAug 9, 2021

--

Just started a Bootcamp and was introduced to some databases like SQL and MongoDB? I’m sure you are here cause you’re interested in SQL and why it's different from NoSQL. Here I will explain the two databases and when you should use one of the two.

Define SQL. What is SQL?

So what is SQL? Well SQL stands for Structured Query Language. Here is a look at what a Structured Query Language looks like below.

“ SELECT * FROM ROCKSTARS”

Now, what does SQL do? What does it allow us to do? It allows you to perform a Create, Read, Update, or Delete operation or what we know as CRUD Operations. This is all through a universal language that is across many different underline relational database engines. Now, what do I mean by underline relational database engines? Well, underline relational database engines are like MySQL, Postgres, Microsoft, and MySQL servers.

Some Underline Relational Database engines.

What’s the structure of SQL?

SQL is a relational database, and relational databases use relations. Relations are basically tables in SQL. These tables store data, will match common characters within the data set. The tables consist of columns and rows, where each row will represent a value, right? A column represents what type of value you want the user to enter, just being more specific. Tables are stored in a MySQL Schema, which is just a system that contains some data and is required by the MySQL server.

In SQL, a table you must have a Primary Key. A primary key is an identifier or what is the value representing. You also must have attributes that point towards to general data about the values. We can also have foreign keys in our tables which are links to other tables in our Schema.

SQL databases have constraints for all tables. For example, The values in the primary key can only be variable characters or like a string so when a user try to enter or update the data with a value that doesn’t match with its identifier the operation will fail.

Whats cool about the SQL Schema and tables is that there are relations, a relationship right? SQL databases allow us to build relationships with other tables , which allow us to perform querues where we can get all data that may have the same id.

What is NoSQL?

NoSQL is just anything that is non-relational, and there’s alot of implementations of NoSQL, some use table structures, document or graph. The basic idea is NoSQL is made to scale with high level actions but your queries are less flexiable here. The structure of NoSQL are table implementations or document implementations that will store JSON Objects. Like I mention before there is graph databases, for example on Instagram or Twitter network a user have followers and your follwers have followers, that represent a Graph database. To clear it all up, all of this rely on key value stores, so for a NoSQL database, you need to know the key you are searching for when using a query.

Difference between SQL and NoSQL. When to use one of them?

SQL:

  1. When your access patterns are not defined.
  2. When you wan to use flexible queries.
  3. When you should use relational queries.
  4. When you want to use constraints on your database.
  5. When you want to use documented access language.

NoSQL:

  1. When you know your access patterns are defined.
  2. When you know your primary key.
  3. When you want to use a high fast performance.

I hope this showed you a great way to seperate, to understand and see the differences between a relational database like SQL and a non-relational database like NoSQL. Make sure to look into more of the SQL database for when you are developing the back end of an application.

Thank you for reading!

--

--