Understanding Databases and SQL: How It Works

This article is a complementary resource to the Learn SQL Basics course.

Understanding Databases and SQL: How It Works

A database is a collection of data organized and stored so that it's easy to access and use.

Database
Database

There are two main types of databases:

1. Non-Relational Database

2. Relational Database


1. Non-Relational Database

Non-relational databases store data in flexible formats like key-value pairs, documents, or graphs. This means the data doesn't have to follow strict rules about how it's stored.

Non-Relational Database
Non-Relational Database

For example, in a non-relational database, you can store customer information in a container like this:

Key Value
id 1
name John
age 25

If you have multiple data, they are stored as:

Key-Value Pairs
Key-Value Pairs

Non-relational databases are useful when data doesn't fit neatly into tables. However, they can be harder to work with when you need well-organized data.

Therefore, we prefer relational databases when structured data storage is required.


2. Relational Database

Relational databases store data in tables with rows and columns.

Example: Organizing Customers

If you're managing customers, you can organize them in a table as follows:

id name age
1 John 25
2 Mary 19

Here, data is neatly organized into rows and columns; this is how relational databases operate.

Since the data is stored in a tabular form, we can use SQL (Structured Query Language) to manage and interact with the data.


What is SQL?

SQL is a tool for working with databases and helps you:

  1. Add or change data: For example, update customer information.
  2. Find specific data: Find the top-purchasing customers.
  3. Organize data: Group customers by age or region.

SQL is powerful and easy to learn, making it a versatile tool for professionals in Data Science, Web Development, and Business Intelligence.


How does SQL work?

The following key components work together to execute SQL queries:

1. Database

2. SQL Query

3. SQL Query Processing

Working of SQL
Working of SQL

1. Database

A database is where data is stored and organized in a structured format.

2. SQL Query

We use SQL to store, manipulate, and retrieve data from the databases. The instructions we write for this are called SQL queries.

For example,

SELECT * FROM Customers;

3. SQL Query Processing

When we execute an SQL query, the database engine processes it in three steps:

SQL Query Processing
SQL Query Processing

This approach ensures SQL queries are valid, flexible, and powerful.


Why does SQL stand out?

1. Easy to Learn

SQL syntax is simple and intuitive.

For example, compare

SELECT CustomerName FROM Customers; 

with plain English—"Select customer names from the customers' table."

2. Versatile Applications

SQL is used in a wide variety of fields like:

  • Data Science and Machine Learning
  • Web and App Development
  • Business Intelligence and Marketing

3. Universal Skill

SQL works with most database systems, handles large datasets, and remains a valuable skill across industries.