Skip to content
Zeni Study
  • Pages
    • Learn Python In 7 Days
      • Day 1 : Variable + if/else
      • Day 2: Loops
      • Day 3 : Array + String
      • Day 4 — Functions
      • Day 5 — Dictionaries - Hashmap
      • Day 6 — Files & Errors
      • Day 7 — Mini Project & Programmer Thinking
    • Machine Coding:
      • Day 1 — Bank account + Wallet :
      • Day 2 : RateLimiter + seat booking
      • Day 3 : Library Management + Classroom Attendance System
      • Day 4 : Bank account and notification system.
      • Day 5 : Key-value and payment processor.
      • Day 6 : Discount engine + Seat booking( in depth)
      • Day 7: Parking lot System :
    • Machine coding extended:
      • Day 7.5 — Parking Lot (Constraint-Heavy Variant)
      • Day 8 : Order + Payment System
      • Day 8 — Extension Round (Mid-Interview Change)
      • Day 9 — Ticket Booking with Expiry (Simulated Time)
      • Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)
    • SQL + DB Thinking course
      • icon picker
        Day 1 — Tables, Rows & Thinking in Data
      • Day 2 — Relationships & Foreign Keys (Thinking in Connections)
      • Day 3 — Filtering, Aggregation & Answering Data Questions
      • Day 4 — JOINs (Combining Tables the Right Way)
      • Day 5 — Subqueries, EXISTS & NOT EXISTS (Thinking in Layers)
      • Day 6 — Indexes, Constraints & How Databases Think
      • Day 7 — Full SQL Interview Simulation (SDE-1 Ready)
      • Extended Day 1 — Core Business Systems (Deep Practice)
      • Extended Day 2 — Booking & Platform Systems (High-Depth Practice)
      • Extended Day 3 — Content & Learning Platforms (Capstone Practice)
    • LLD: Java
      • DAY 1 — Core Foundations (SDE-2 Level)
      • DAY 2 — State, Time & Domain Correctness
      • DAY 3 — Extensibility & Failure Handling (SDE-2 Core Signal)
      • DAY 4 — Concurrency, Scheduling & Consistency (SDE-2 Critical)
      • DAY 5 — Workflow Design & Config-Driven Systems (SDE-2+)
      • DAY 6 — Eventing & Usage-Based Systems (Advanced SDE-2)
      • DAY 7 — Interview Simulation (Hard, Production-Grade)
      • Hidden Edge Cases Interviewers Expect (Day-wise)
      • Detailed Testing file:
    • Assignment:
      • If else Practice Set

Day 1 — Tables, Rows & Thinking in Data

🟢 Day 1 — Tables, Rows & Thinking in Data

🎯 Day 1 Outcome

By the end of Day 1, the student should be able to:
Understand what a table really represents
Design a basic schema correctly
Insert and fetch data using SQL
Think in rows, not files
Answer why a schema is designed in a certain way
Today is not about SQL syntax. Today is about how data lives.

1️⃣ How to Think About Databases (Teaching Script)

Start with This Question

“If I restart my backend server, where does my data go?”
Answer:
Variables → gone ❌
Lists / dicts → gone ❌
Database → still there ✅
A database is long-term memory for software.

2️⃣ What Is a Table? (Very Important)

Wrong Mental Model ❌

“Table is like Excel”

Correct Mental Model ✅

A table stores many objects of the same type.
Example:
User table = many users
Order table = many orders

Mapping Real World → Table

Real World
Database
One user
One row
User attributes
Columns
User identity
Primary key
There are no rows in this table

3️⃣ Rows, Columns & Primary Key

Example: User Entity

In real life, a user has:
id
name
email
created time
So the table becomes:
CREATE TABLE users (
user_id INT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP
);

Explain Line by Line (Student Must Read)

users → collection of users
user_id → unique identity
PRIMARY KEYcannot be duplicate, cannot be NULL
VARCHAR(100) → text with limit
created_at → when user was created
🧠 If you don’t have a primary key, you don’t really have a table.

4️⃣ Why Not Use Email as Primary Key? (Interview Thinking)

Ask the student:
Can email change? → Yes
Can user have multiple emails? → Possibly
Is email long? → Yes
So:
Primary key should be stable, small, and meaningless.
That’s why IDs exist.

5️⃣ Basic SQL Operations (Must Know)

Insert Data

INSERT INTO users (user_id, name, email, created_at)
VALUES (1, 'Amit', 'amit@gmail.com', '2024-01-01');
Each INSERT = one row

Fetch All Data

SELECT * FROM users;
Think: “Give me all users”

Fetch Specific Columns

SELECT name, email FROM users;
Don’t fetch unnecessary data (interviewers notice this)

Fetch by ID (Most Common Query)

SELECT * FROM users WHERE user_id = 1;
This should return at most one row (because primary key is unique)

6️⃣ Filtering Data with WHERE

SELECT * FROM users
WHERE created_at >= '2024-01-01';
Read in English:
“Give me users created after Jan 1, 2024”

7️⃣ Counting Rows (Extremely Common)

SELECT COUNT(*) FROM users;
“How many users exist?”

8️⃣ Common Beginner Mistakes (Read Carefully)

❌ No primary key ❌ Using email/name as primary key ❌ Fetching all columns always ❌ Thinking table = file

9️⃣ Practice Problems (DO THESE)

Problem 1 — Create Table

Create a table employees with:
emp_id
name
department
joining_date

Problem 2 — Insert Data

Insert 3 employees into table.

Problem 3 — Fetch Queries

Write queries to:
Fetch all employees
Fetch only names
Fetch employee with emp_id = 2
Fetch employees from a specific department

Problem 4 — Count

Count how many employees exist.

🔍 HINTS (Read Only If Stuck)

Use PRIMARY KEY
Use WHERE for filtering
Use COUNT(*) for counting
SQL reads like English (left → right)

✅ Solutions (Read After Attempting)

Solution 1 — Table Creation

CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(50),
joining_date DATE
);

Solution 2 — Insert

INSERT INTO employees VALUES
(1, 'Rahul', 'Engineering', '2022-01-10'),
(2, 'Neha', 'HR', '2023-03-15'),
(3, 'Amit', 'Engineering', '2021-06-20');

Solution 3 — Queries

SELECT * FROM employees;

SELECT name FROM employees;

SELECT * FROM employees WHERE emp_id = 2;

SELECT * FROM employees WHERE department = 'Engineering';

Solution 4 — Count

SELECT COUNT(*) FROM employees;

🧠 Reflection Questions (Must Answer)

Why do we need a primary key?
Why not store multiple users in one row?
What happens if two rows have same emp_id?
Why should IDs not carry meaning?

⭐ Day 1 Golden Rule

Databases store facts, not logic. Logic lives in code.

 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.