GimmeJob
Sign in
Databases, SQL & BI · SQL · Chapter 10 / 17

SQL learning path

INSERT, UPDATE, DELETE & transactions

Write statements change state. In a real environment, the safe workflow is: understand the target set with SELECT, perform the change inside a transaction where possible, verify the result, then commit deliberately.

The site's SQL runner is isolated in memory. Changes persist only within that runner session and Reset restores the sample database.

INSERT

Always list target columns unless there is a very specific reason not to. This makes the statement resilient to schema changes and self-documenting.

SQL
SQLite · sample DB · browser sandbox
Result
Run the query to see the result.

UPDATE with a bounded predicate

Before UPDATE, run the same WHERE clause as a SELECT and inspect every row it would touch.

SQL
SQLite · sample DB · browser sandbox
Result
Run the query to see the result.

An UPDATE without WHERE can modify every row.

DELETE with a bounded predicate

DELETE removes rows; DROP removes schema objects. For production work, verify the target set first and consider whether soft deletion/audit requirements apply.

SQL
SQLite · sample DB · browser sandbox
Result
Run the query to see the result.

Transactions and atomicity

A transaction groups changes into one logical unit: either all intended changes commit or they can be rolled back. PostgreSQL's tutorial emphasizes this all-or-nothing property.

SQL
SQLite · sample DB · browser sandbox
Result
Run the query to see the result.

The exact locking and isolation behavior depends on the database engine.

ROLLBACK and SAVEPOINT

ROLLBACK abandons uncommitted work. SAVEPOINT establishes a point within a transaction that can be rolled back without discarding earlier transaction work. Savepoints are useful in complex migrations and controlled batch operations.

Read-modify-write race conditions

A transaction does not automatically make every application pattern safe. If two transactions read the same current value and then both write based on it, isolation level and locking determine what can happen. Prefer atomic SQL updates or database constraints when possible.

Safe write checklist

  1. Identify rows with SELECT.
  2. Confirm expected row count and business scope.
  3. Use explicit transaction control where appropriate.
  4. Execute the mutation.
  5. Re-query invariants and affected rows.
  6. Commit only after verification; otherwise roll back.

Practice: in the runner, update one pending order to paid, inspect it, then press Reset and confirm the original state returns.

Source registry

4 chapter references · Under review
PostgreSQL 18 Tutorial

Primary semantic reference for relational concepts, querying, joins, aggregates, updates, deletes, views, foreign keys, transactions, and window functions.

PostgreSQL Global Development Group · official documentation
Source ↗
PostgreSQL 18 — Transactions

Primary reference for atomic transactions, BEGIN/COMMIT/ROLLBACK, savepoints, and transaction reasoning.

PostgreSQL Global Development Group · official documentation
Source ↗
SQLite — Transaction

Runtime-aligned reference for SQLite transaction behavior and explicit transaction control.

SQLite · official documentation
Source ↗
SQL Tutorial

Supplementary examples and exercises for foundational SQL statements; used as a breadth reference rather than the authority for engine-specific behavior.

W3Schools · tutorial
Source ↗