Basics of SQL

Getting your Trinity Audio player ready...

Imagine this…

You open an Excel file and see 50,000 rows of sales data.

No structure.
No connection.
Same customer name written 20 times differently.
Product names repeated everywhere.

Confusing, right?

Now imagine everything is properly organized.

  • Customers stored in one place
  • Products stored in one place
  • Sales stored in one place
  • Everything connected automatically

That is where a database comes in.

Let’s understand this in the simplest way possible 👇


What is a Database?

A database is just a smart digital storage system.

Think of it like a cupboard.

Inside the cupboard:

  • One drawer for employees
  • One drawer for products
  • One drawer for customers
  • One drawer for sales

Each drawer = a table.

All drawers together = a database.

Simple 😊


What is a Table?

A table is where actual data lives.

It looks like an Excel sheet:

  • Rows → Individual records
  • Columns → Information fields

Let’s take a small example from our FMCG company.


Employees Table

idnamedepartmentsalary
1AmitSales40000
2PriyaFinance35000

Each row is one employee.


Products Table

idproduct_nameprice
1Classic Cola25
2Chips20

Each row is one product.


Now comes something very important.

Look at the “id” column in both tables.

Why is it there?


What is a Primary Key?

A Primary Key is a unique identity number for each row.

Just like:

  • Your Aadhaar number
  • Your Employee ID
  • Your Roll number

Two people cannot share the same Aadhaar number.

Similarly:

Two rows cannot share the same Primary Key.

In Employees table:

idname
1Amit
2Priya

Here:

  • 1 belongs only to Amit
  • 2 belongs only to Priya

That “id” is the Primary Key.

It:

  • Cannot be duplicate
  • Cannot be NULL

It uniquely identifies a record.


What is a Foreign Key?

Now imagine this sales record:

sale_idcustomer_idproduct_idquantity
1325

You don’t see customer name.
You don’t see product name.

Why?

Because instead of storing full details again and again,
we store only their IDs.

  • customer_id → comes from Customers table
  • product_id → comes from Products table

These IDs are called Foreign Keys.

A Foreign Key connects one table to another.

Think of it like:

📞 A contact number connecting you to a person.

Without that number, connection is lost.


How Tables Are Connected

Let’s say:

Customer with id = 3 buys 10 times.

In Sales table, customer_id = 3 will appear 10 times.

This means:

👉 One customer → Many sales
👉 One employee → Many sales

This is called One-to-Many relationship.

And this is the backbone of SQL joins (which we will learn soon).


What Happens Without Keys?

If we don’t use Primary Key and Foreign Key:

  • Customer name may be written differently
  • Duplicate data increases
  • Reports become wrong
  • Storage becomes heavy
  • Data becomes messy

This is exactly what happens in poorly managed Excel files.

Databases solve this problem.


Why This Matters for Data Analysts

As a Data Analyst or MIS professional, you will:

  • Join multiple tables
  • Generate reports
  • Fix wrong data
  • Remove duplicates
  • Clean messy entries

If you don’t understand:

  • Primary Key
  • Foreign Key
  • Table relationships

You will struggle with JOIN queries later.

This is the foundation.


Quick Recap (Super Simple)

Database → Collection of tables
Table → Data stored in rows and columns
Primary Key → Unique identity of each row
Foreign Key → Connects tables together

If this is clear, you are officially ready for real SQL learning.


Summary

A database is an organized digital storage system that keeps related data in one place. Inside a database, data is stored in tables, which look like Excel sheets with rows and columns.

Each table has a Primary Key, a unique identifier that ensures every record is different and prevents duplication. A Foreign Key connects one table to another by referencing its Primary Key. These keys create relationships between tables, reduce data repetition, and maintain accuracy.

Understanding databases, tables, and keys is essential for writing SQL queries, performing joins, and becoming a confident Data Analyst or MIS professional.


What’s Next?

In the next article:

👉 Data Types in SQL

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Translate »
Scroll to Top