Intro to SQL & NoSQL Databases
By: Prince Barpaga
Tags: Data Science, Sql, NoSQL, Nosql Database, Database

What is a Database?

A Database is a collection of data stored in a format that can easily be accessed. In order to manage our databases, we use a software application called DBMS (Database Management System).

Udacity — Intro to Relational Databases

We connect to a DBMS and give instructions to query the data. The DBMS will execute our instructions and send results back. There are several Database Management Systems out there and these are classified into two categories: Relational & NoSQL.

Relational Database

In a Relational Database, we store data in tables that are connected or linked to each other using relationships. Each table stores data about a specific type of object, like (Customers, Orders, Product).

The language that we use to communicate and work with databases is called SQL (Structured Query Language).

There are many RDBMS (Relational Database Management Systems) out there, the most popular ones are MySQL, SQL Server, Oracle, PostgreSQL. Relational Database is ACID (Atomicity, Consistency, Isolation, Durability)

Atomic: all of the work in a transaction completes (commit) or none of it completes. Consistent: a transaction transforms the database from one consistent state to another consistent state. Isolated: the results of any changes made during a transaction are not visible until the transaction has been committed. Durable: the results of a committed transaction survive failures.

Advantages of RDBMS over NoSQL

Better for relational data Normalization (reduces redundancy and increases performance) Uses SQL Data Integrity ACID Compliance

NoSQL

There has been a massive increase in data volume within the last decade due to social media networks, search engines, etc. Big Data refers to data sets that are so large where traditional methods of storage & processing are inadequate. The challenge with this is in storage, capture, analysis & transfer. This is where NoSQL comes in. In order to manage and work with these massive sets of data also known as Big Data or real-time webapps, we use NoSQL.

NoSQL stands for “NOT ONLY SQL”. NoSQL systems don’t understand SQL, they have their own query language. In non-relational databases, we don’t have tables or relationships. These databases are very different from relational databases.

NoSQL Database systems are BASE (Basically, Available, Soft-state, Eventually Consistent)

Basically Available: the system seems to work all the time, some parts of systems remain available on failure. Soft state: it does not have to be consistent all the time. Eventually Consistent: as the data is written, the latest version is on at least one node. The data is then replicated to other nodes within the system. Eventually, the same version is on all nodes.

Advantages of NoSQL over RDBMS

Handles Big Data Data Models — no predefined schema Data Structure — NoSQL handles unstructured data Cheaper to manage Scaling — Scale out / horizontal scaling

Unstructured Data

Cannot be displayed in rows, columns, and relational databases Images, audio, video, word processing files, e-mails, spreadsheets Estimated 80% of enterprise data Requires more storage More difficult to manage and protect with legacy solutions.

Scaling Vertically VS Scaling Horizontally

With Scaling Up (Vertically), we need to add components, storage, drives, memory, network ports, and other resources are very expensive.

With Scaling Out (Horizontally) which is what most NoSQL systems do. To scale out, you need a distributed cluster of servers. However, this can run into a few problems. It can lead to a network partition (failures of a network that causes communication interruptions).

Types of NoSQL Databases

Document Databases [MongoDB, CouchDB] — stores data in JSON / BSON Column Databases [Apache Cassandra] — good for analytics Key-Value Stores [Redis, Couchbase Server] — very simple like Hash, Array Cache Systems [Redis, Memcache] — used as a cache system for temporary values. Graph Databases [Neo4J] — based on nodes, and have relationships with other nodes, used for social networks.

Relational VS Document

Free additional resources to learn more:

I hope you found this article helpful. If you found it helpful, make sure to stay connected. Wish you all the best in your future career.

Connect with me on LinkedIn

Follow me on Instagram