Kazi Rahamatullah
Kazi Rahamatullah
AboutProjectsBlogContact
UsesBooks
ResumeView CV
Kazi Rahamatullah

© Copyright 2026 Kazi Rahamatullah

AboutProjectsBlogBooksUses
Twitter/XGitHubProduct HuntCodeSandbox
Back to Blog
MERNMySQLSQLPrismaDatabase DesignBackend

MERN Course: MySQL Essentials

Weeks 19–21 of the MERN syllabus — relational design, SQL CRUD, joins, constraints, indexing, transactions, Prisma/Sequelize ORMs, and capstone project.

Jul 11, 20267 min read

Introduction

SQL skills complement MongoDB in full-stack careers. This guide completes the MySQL Essentials syllabus with schema design, safe queries, and ORM patterns for Node.js APIs.

Course Reference

Quick index

#TopicDescription
1Diving into the World of DatabasesRelational databases store data in tables with strict schemas.
2Database Design FundamentalsNormalize to reduce duplication.
3SQL Fundamentals (SELECT)SELECT retrieves data.
4Data Manipulation (INSERT, UPDATE, DELETE)INSERT adds rows, UPDATE modifies, DELETE removes.
5Constraints and Data IntegrityNOT NULL, UNIQUE, CHECK, DEFAULT, and FOREIGN KEY enforce rules at the database layer — not just in app code..
6Joins and SubqueriesINNER JOIN returns matching rows only.
7Indexing and TransactionsB-tree indexes accelerate WHERE/JOIN/ORDER BY.
8ORMs: Sequelize or PrismaORMs map tables to models in TypeScript.
9Final MySQL ProjectBuild a library, todo, or movie app with normalized schema, CRUD API via Express + Prisma/Sequelize, and pagination..

Week 19: MySQL Foundations

1. Diving into the World of Databases

Relational databases store data in tables with strict schemas. MySQL excels at structured data, transactions, and complex joins — common in enterprise MERN+SQL stacks.

  • Tables = rows + columns with defined types
  • Primary keys uniquely identify rows
  • SQL is the standard query language for relational DBs

Example:

sql
CREATE DATABASE mern_course;
USE mern_course;

Note

Many teams use PostgreSQL instead of MySQL — SQL skills transfer. Syntax differs slightly (JSON types, extensions).

Tip

Apply this in your Week 19 course project before moving on.

Performance

Pick one SQL engine per project. MySQL 8+ supports window functions and CTEs for analytics queries.

Back to index


2. Database Design Fundamentals

Normalize to reduce duplication. Identify entities (User, Post, Comment), attributes, and relationships (1:N, N:M).

Example:

sql
CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) NOT NULL UNIQUE,
  name VARCHAR(120) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
 
CREATE TABLE posts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  title VARCHAR(200) NOT NULL,
  slug VARCHAR(220) NOT NULL UNIQUE,
  body TEXT NOT NULL,
  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

Note

Use ON DELETE CASCADE carefully — deleting a user removes all their posts. Sometimes RESTRICT or soft deletes are safer.

Tip

Apply this in your Week 19 course project before moving on.

Performance

Index foreign keys (user_id) — JOIN and WHERE filters on FK columns are common.

Back to index


3. SQL Fundamentals (SELECT)

SELECT retrieves data. WHERE filters, ORDER BY sorts, LIMIT paginates. Always parameterize queries — never string-concatenate user input.

Example:

sql
SELECT id, title, slug, created_at
FROM posts
WHERE user_id = ?
ORDER BY created_at DESC
LIMIT 10 OFFSET 0;

Note

The ? placeholder is filled by your driver (mysql2, Prisma) — prevents SQL injection.

Tip

Apply this in your Week 19 course project before moving on.

Performance

Avoid SELECT * in APIs — fetch only columns the client needs.

Back to index

Week 20: CRUD, Integrity & Joins

4. Data Manipulation (INSERT, UPDATE, DELETE)

INSERT adds rows, UPDATE modifies, DELETE removes. Wrap multi-step changes in transactions.

Example:

sql
START TRANSACTION;
 
INSERT INTO posts (user_id, title, slug, body) VALUES (1, 'MERN Guide', 'mern-guide', '...');
 
UPDATE users SET name = 'Kazi R.' WHERE id = 1;
 
DELETE FROM posts WHERE slug = 'draft-post';
 
COMMIT;

Note

Use ROLLBACK on error. In Node, use connection.beginTransaction() / commit() / rollback().

Tip

Apply this in your Week 20 course project before moving on.

Performance

Batch inserts with multi-row INSERT instead of one INSERT per row in loops.

Back to index


5. Constraints and Data Integrity

NOT NULL, UNIQUE, CHECK, DEFAULT, and FOREIGN KEY enforce rules at the database layer — not just in app code.

Example:

sql
ALTER TABLE posts
  ADD CONSTRAINT chk_title_length CHECK (CHAR_LENGTH(title) >= 3);
 
ALTER TABLE users
  ADD COLUMN status ENUM('active', 'suspended') NOT NULL DEFAULT 'active';

Note

Duplicate validation in app + DB is fine — DB is the last line of defense if API validation is bypassed.

Tip

Apply this in your Week 20 course project before moving on.

Performance

Unique indexes speed lookups and enforce constraints — both benefits in one.

Back to index


6. Joins and Subqueries

INNER JOIN returns matching rows only. LEFT JOIN keeps all left rows with NULLs where no match. Subqueries nest SELECT inside WHERE/FROM.

Example:

sql
SELECT p.title, p.slug, u.name AS author
FROM posts p
INNER JOIN users u ON u.id = p.user_id
WHERE p.created_at >= '2026-01-01'
ORDER BY p.created_at DESC;
 
-- Subquery: users with more than 5 posts
SELECT name FROM users
WHERE id IN (
  SELECT user_id FROM posts GROUP BY user_id HAVING COUNT(*) > 5
);

Note

Prefer JOINs over correlated subqueries in hot paths — optimizers often handle JOINs better.

Tip

Apply this in your Week 20 course project before moving on.

Performance

Explain plans (EXPLAIN ANALYZE) before adding indexes blindly.

Back to index

Week 21: Performance, ORMs & Project

7. Indexing and Transactions

B-tree indexes accelerate WHERE/JOIN/ORDER BY. Transactions guarantee ACID — all steps succeed or none do.

Example:

sql
CREATE INDEX idx_posts_user_created ON posts (user_id, created_at DESC);
 
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

Note

Too many indexes slow INSERT/UPDATE. Index columns you filter/sort on — not every column.

Tip

Apply this in your Week 21 course project before moving on.

Performance

Use READ COMMITTED or REPEATABLE READ isolation based on consistency needs — default varies by engine.

Back to index


8. ORMs: Sequelize or Prisma

ORMs map tables to models in TypeScript. Prisma offers type-safe queries and migrations; Sequelize is mature and flexible.

Example:

typescript
// Prisma schema excerpt
model Post {
  id        Int      @id @default(autoincrement())
  title     String
  slug      String   @unique
  author    User     @relation(fields: [authorId], references: [id])
  authorId  Int
  createdAt DateTime @default(now())
}
 
// Query
const posts = await prisma.post.findMany({
  where: { authorId: 1 },
  select: { title: true, slug: true },
  orderBy: { createdAt: 'desc' },
  take: 10,
})

Note

Raw SQL escape hatches exist when ORM queries get awkward — aggregation pipelines, complex reports.

Tip

Apply this in your Week 21 course project before moving on.

Performance

Prisma connection pooling + @prisma/client edge bundle matter for serverless (Vercel) cold starts.

Back to index


9. Final MySQL Project

Build a library, todo, or movie app with normalized schema, CRUD API via Express + Prisma/Sequelize, and pagination.

  • Draw ERD before writing SQL
  • Seed database with realistic sample data
  • Add integration tests against a test DB container

Note

Use migrations from day one — never manually alter production schema without versioned migration files.

Tip

Apply this in your Week 21 course project before moving on.

Performance

Connection pool size ≈ (CPU cores × 2) for typical Node APIs — avoid one connection per request.

Back to index


Share this article

XLinkedInFacebook
Kazi Rahamatullah

Written by

Kazi Rahamatullah

FullStack Developer

X / TwitterGitHubLinkedIn

Subscribe to my newsletter

Stay up to date and get notified when I share new contents.

No spam ever, unsubscribe anytime