← Lesson
BitWithBite
SQL · Quick Reference

Lesson 12 — Database Design & ERDs Cheat Sheet

SQL
In one line: Database normalization serves three core goals:

Key Ideas

1Normalization Goals. Database normalization serves three core goals:
2Entity Relationship Diagrams (ERD). An ERD is a visual blueprint of your database. It shows:
3Relationship Types with Code. The three fundamental relationship types determine where foreign keys go and whether junction tables are needed.
4One-to-One Relationships. A one-to-one relationship stores optional or extension data in a separate table, linked by sharing the same primary key value.

Code Examples

-- One-to-Many: one customer has many orders CREATE TABLE customers ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100) NOT NULL, email VARCHAR(150) UNIQUE ); CREATE TABLE orders ( id INT PRIMARY KEY AUTO_INCREMENT, custo...
-- One user has one profile (optional extension table) CREATE TABLE user_profiles ( user_id INT PRIMARY KEY, -- same as users.id bio TEXT, avatar_url VARCHAR(300), FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE );