Rana Maninder Singh
Lesson 1 of 11SQL & DBMS (MySQL)

Introduction to DBMS

Lesson opener

In one line: Tables, keys, schemas - how business data maps to relational databases.

Why it matters: Without a picture of how tables connect, you guess which column links what - and your joins return garbage or duplicate rows.

Before this lesson: AI Prompting capstone

Before you start

What you will learn

Tables, keys, schemas — how business data maps to relational databases.

Types of databases — SQL, columnar, time-series, graph, document, vector, and more
Types of databases — SQL, columnar, time-series, graph, document, vector, and more

This course focuses on SQL (relational) databases — the type behind most business ERP, CRM, and reporting systems.

SQLite = single-file, no server — fine for local demos and prototyping, not what enterprise/ERP teams run in production (that's MySQL, Postgres, SQL Server, Oracle).

Concepts

TermMeaningLab example
DatabaseContainerlearnings_lab
TableRows + columnscustomers, sales
Primary keyUnique row idcustomer_id
Foreign keyLink to other tablesales.customer_id → customers
SchemaStructure definitioncolumn types
VIEWSaved query with a name (looks like a table)See CTE & Views

Primary keys and foreign keys — in depth

Primary key (PK): One column (or a small combo) that uniquely identifies each row in a table. No duplicates, no NULLs in a well-designed key.

TablePKWhy it works
customerscustomer_idOne ID per person — C001 never appears twice
salesorder_idOne ID per order line

Foreign key (FK): A column in the child table that points to the parent's PK. It enforces the link: "this order belongs to that customer."

sales.customer_id  →  customers.customer_id
     (FK)                    (PK)

What goes wrong without keys:

ProblemSymptom
Duplicate PKTwo customers share C001 — revenue double-counts
Orphan FKsales row references C999 but no such customer — join drops or shows NULL
Missing FKYou join on segment name instead of ID — "Gold" typos break matches

Try it in Workbench: DESCRIBE customers; — look for PRI in the Key column on customer_id.


ETL — how data gets into the database

ETL = Extract (pull from source) → Transform (clean, type, dedupe) → Load (write to tables). Excel Power Query and SQL imports both follow this pattern.


Tutorial — ER diagram (text)

[Customer–sales relationship diagram]

WHY: Without a picture of how tables connect, you guess which column links what — and your joins return garbage or duplicate rows.

WHEN: You're onboarding to a new dataset and need to explain "one customer, many orders" to a teammate before writing any SQL.

customers (1) ──< sales (many)

Breaking it down:

Use this when: You're sketching the data model on a whiteboard before building a revenue-by-customer report.


Tutorial — Explore in Workbench

[First look at a table]

WHY: Jumping straight into complex queries on a table you haven't seen yet means wrong column names, surprise data types, and accidental full-table scans.

WHEN: You just got access to learnings_lab and want a quick sanity check before the standup.

USE learnings_lab;
DESCRIBE customers;
SELECT * FROM customers LIMIT 5;

Breaking it down:

Use this when: Someone hands you a new table name and you need to know what's inside before writing filters or joins.


Compare Excel vs database

Filter, sort, group, join — the same job in three tools:

Excel vs Python vs SQL — same task, three tools
Excel vs Python vs SQL — same task, three tools
ExcelMySQL
SheetTable
VLOOKUPJOIN
PivotGROUP BY
Save filePersistent DB + queries

Install DB: MySQL setup.


Essential commands

Command / actionWhat it does
USE database_name;Select which database to query.
DESCRIBE table_name;Show table structure.
SHOW TABLES;List tables in current database.
SELECT * FROM t LIMIT n;Safe preview of table contents.

Practice

Before each query, name the three SQL beats — Source → Pattern → Result (SQL translation of Input → Logic → Output — see sql2). Exploration queries still use the habit: name the table as Source, the command pattern, and what shape you expect back.

Do this now:

  1. Run DESCRIBE + SELECT … LIMIT on customers (worked model below).
  2. Repeat the same habit on sales.
  3. Draw both tables on paper and label PK / FK.
  4. Save notes / snippets as you explore (optional script name: 01_intro.sql).

Example framing for task 1:

-- Source: customers (all columns — exploring structure)
-- Pattern: DESCRIBE + SELECT with LIMIT
-- Result: column list / keys, then 5 sample rows (not a full dump)

USE learnings_lab;
DESCRIBE customers;
SELECT * FROM customers LIMIT 5;

Framing prompts for the rest (fill these blanks before each step):

  1. Source: ___

Pattern: ___

Result: ___

  1. Source: ___

Pattern: ___

Result: ___

Where This Connects

Scale-up: Once one OLTP database isn't enough for analytics at volume, teams land data in a cloud warehouse (e.g. BigQuery, Snowflake, Redshift) and often model transforms with dbt. Awareness only; not taught on this site.

Cross-ecosystem: Same filter / aggregate / join job on this site (trio diagram above): Spreadsheets intro and Pandas basics. Dialect deepening: PostgreSQL after this MySQL track.

Checklist

  • [ ] I can name PK and FK
  • [ ] Both tables described
  • [ ] Next: SQL commands