Skip to content

Data Modeling

Billy Bunn edited this page Mar 27, 2019 · 3 revisions

Largely based on SQL vs NoSQL or MySQL vs MongoDB, a video by Academind

SQL vs NoSQL

What does SQL even mean?

SQL is an acronym that stands for Structured Query Language.

Meaning, SQL is not a database, it's a language. It's a language to write queries to a database. In this language, you use certain keywords built-in and parameters that refer to fields/records in a database. You can do more than just get stuff from a database with SQL, you can also insert, update, and delete data or manipulate the relationships between tables in a database. A SQL query to retrieve something from a database might look like this:

SELECT id, name, price FROM products

In this query, SELECT and FROM are SQL keywords and the other words are parameters that refer to things in the database.

When we ask the question "SQL or NoSQL?", we're refering to the databases that work with these languages.

Database Structure

Databases are organized collections of information.

SQL

SQL databases work in a specific way and adheres to a predefined structure called a schema. They use tables to store data, which often have relationship with each other.

Schemas

A schema defines the tables that are inside the database and the fields (columns) that must be in each record (row). All records in a SQL database must adhere to the format defined by the schema. Even if a record doesn't have any data to store for a specific field (column), it must provide something, even null, to fill that field for that record. Additionally, a record cannot contain some extra information that doesn't fit into the schema-defined fields. If there is no field for "temperature", you cannot create a query to record some information to that field (it doesn't exist if it isn't defined by the schema).

Normalization

So all records in a table have to adhere to the schema. Which means that when data is add to a table in a SQL database, it must be normalized, meaning it must be formatted so it adheres to the schema. We have to take off any extra information there isn't a field for.

Relations

The other defining feature of a SQL database are the relationships between tables. You might hear the term "relational database". Typically, you'll have multiple tables in a SQL database where records in one table are connected to one another. For an online store, you might have a "customers" table that contains contact information and an "orders" table that's contains all customer orders. The "orders" table would be connected to the "customers table with a piece of data like an id.

There are three types of these table relations:

  • One-to-one - one record in a table is connected to another (single) record in a different table
  • One-to-many - one record in a table is connected to many other records in a different table
  • Many-to-many - multiple records in a table are connected to multiple records in another table (this might be a table that connects two tables together)

NoSQL (MongoDB)

MongoDB is the most popular NoSQL database. It gets its name from "humongous", as it's made to hold


Resources

Read

Watch

Bookmark

Clone this wiki locally