Skip to content
Learn Netverks

Lesson

Step 9/36 25% through track

insert-update-delete

INSERT, UPDATE, DELETE

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

This lesson

This lesson teaches INSERT, UPDATE, DELETE: the SQL patterns, schema habits, and query reasoning you need before advancing in SQL.

Teams query INSERT, UPDATE, DELETE on every SQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply INSERT, UPDATE, DELETE 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.

When you can explain the previous lesson's ideas without copying example queries verbatim.

DML statements change stored data. Application ORMs generate these, but every developer should read the raw SQL—especially WHERE on updates and deletes.

INSERT

INSERT INTO customers (name, email)
VALUES ('Grace', 'grace@example.com');

INSERT INTO orders (customer_id, total, ordered_at)
VALUES (1, 25.00, '2025-03-01');

Practice: Run in SQLite, DB Fiddle, or Postgres. Create the customers/orders sample from the relational-model lesson if needed.

UPDATE

UPDATE orders
SET total = total * 0.9
WHERE id = 101;

-- Always preview first:
SELECT id, total FROM orders WHERE id = 101;

Rule: Never run UPDATE without WHERE unless you intend to touch every row.

DELETE

DELETE FROM orders
WHERE id = 103;

-- Safer pattern: SELECT count first
SELECT COUNT(*) FROM orders WHERE customer_id = 99;

Deletes are permanent without backups or transactions. Soft deletes (status column) are common in apps.

Important interview questions and answers

  1. Q: INSERT vs UPSERT?
    A: Plain INSERT fails on duplicate keys; UPSERT/MERGE variants update or ignore—dialect-specific.
  2. Q: Why preview with SELECT?
    A: Confirms the WHERE clause matches intended rows before irreversible changes.

Self-check

  1. Which DML statement removes rows?
  2. What happens if you UPDATE without a WHERE clause?

Pitfall: UPDATE without WHERE touches every row—use transactions in production consoles.

Interview prep

UPDATE without WHERE?

Updates every row in the table—usually accidental.

DELETE vs TRUNCATE?

DELETE removes rows with optional WHERE; TRUNCATE clears table fast (dialect rules vary).

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

  • RETURNING use?
  • Upsert idea?

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