Connect → USE database → inspect with SHOW / DESCRIBE → run SELECT with LIMIT → EXPLAIN slow queries → add indexes in staging.
Exploration
USE practice;
SHOW TABLES;
DESCRIBE orders;
SELECT * FROM orders WHERE status = 'open' LIMIT 10;
EXPLAIN SELECT * FROM orders WHERE customer_id = 42;Practice: Copy SQL into the mysql client, local MySQL/MariaDB, or DB Fiddle (MySQL dialect).
Safe habits
- Always
LIMITexploratory SELECT on large tables - Preview UPDATE/DELETE with SELECT … WHERE first
- Run DDL migrations in transactions where possible (InnoDB)
- Separate dev/staging/prod credentials
Sample seed data
CREATE TABLE IF NOT EXISTS products (
id INT AUTO_INCREMENT PRIMARY KEY,
sku VARCHAR(32) NOT NULL,
name VARCHAR(255) NOT NULL,
price DECIMAL(10,2) NOT NULL
);
INSERT INTO products (sku, name, price) VALUES
('A1', 'Widget', 9.99),
('B2', 'Gadget', 24.50);
Important interview questions and answers
- Q: EXPLAIN purpose?
A: Shows access type (ALL vs ref vs range) and rows examined—index tuning starting point. - Q: LIMIT on exploration?
A: Prevents dumping millions of rows into terminal or GUI.
Self-check
- What should you run before UPDATE with a new WHERE clause?
- What does DESCRIBE show?
Challenge
Seed practice tables
USE practice- Run products seed SQL from lesson.
EXPLAINa filter on customer_id or status.
Done when: you see table list and EXPLAIN output with type and key columns.
Interview prep
- EXPLAIN?
Shows access path and index use for a SELECT.
- Before UPDATE?
SELECT with same WHERE to verify affected rows.