Skip to content
Learn Netverks

Lesson

Step 30/36 83% through track

er-modeling-basics

ER modeling basics

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches ER modeling basics: the SQL patterns, schema habits, and query reasoning you need before advancing in SQL.

Teams query ER modeling basics on every SQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply ER modeling basics in contexts like: Postgres, MySQL, SQLite, warehouses, and ORMs that still expose SQL.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path.

Toward the end of the track—consolidate before dialect tracks, interview prep, and production checklist lessons.

Entity-Relationship (ER) diagrams visualize tables as entities, columns as attributes, and lines as relationships (one-to-many, many-to-many). Design on paper before writing CREATE TABLE.

Entities and relationships

  • One-to-many — one customer, many orders (FK on orders)
  • Many-to-many — students and courses via enrollment junction table
  • One-to-one — user and profile split for optional heavy columns

Junction table

CREATE TABLE students (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL
);

CREATE TABLE courses (
  id INTEGER PRIMARY KEY,
  title TEXT NOT NULL
);

CREATE TABLE enrollments (
  student_id INTEGER NOT NULL,
  course_id INTEGER NOT NULL,
  enrolled_at TEXT,
  PRIMARY KEY (student_id, course_id),
  FOREIGN KEY (student_id) REFERENCES students(id),
  FOREIGN KEY (course_id) REFERENCES courses(id)
);

Practice: Sketch ER on paper, then implement in SQLite.

Cardinality notation

Crow's foot diagrams mark “many” sides. Validate designs by walking sample user stories: enroll student, list course roster, drop course.

Important interview questions and answers

  1. Q: Many-to-many implementation?
    A: Two foreign keys in a junction table with composite primary key.
  2. Q: When split one-to-one?
    A: Optional profile data, security isolation, or performance partitioning.

Self-check

  1. How do you model students taking many courses?
  2. Where does the foreign key go in one-to-many customer/orders?

Tip: Many-to-many always needs a junction table with two foreign keys.

Interview prep

Many-to-many?

Junction table with FKs to both entities.

One-to-many FK placement?

Foreign key goes on the many side.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Entity naming?
  • M:N bridge table?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump