Pcornel
Databases

SQL Operations

Cheat sheet · https://pcornel.dk/topic.php?topic=6086

Back to the Topic

Answer

SQL operations read and change data: SELECT, INSERT, UPDATE, DELETE, plus DDL (CREATE, ALTER) and transaction control (BEGIN, COMMIT, ROLLBACK).

Remember

Run changes inside a transaction and check the affected row count before COMMIT. Always use a WHERE clause on UPDATE/DELETE and test it as a SELECT first. Use parameters, never string concatenation (SQL injection).

First checks

  • SELECT count(*) … WHERE … — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

statement parsed → planned → executed in a transaction → committed

Where it usually breaks

Failures include missing or broad WHERE clauses, joins that multiply rows, implicit conversions defeating indexes, long transactions holding locks, DDL blocking workloads and assuming rollback exists for every engine/DDL operation.

SQL Operations verification boundary matrix

BoundaryInspectHealthy interpretationDo not infer
IntentSELECTIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeINSERT / UPDATE / DELETE / JOINsOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateFiltering and aggregationIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeDDL basicsThe original bounded check succeeds in the same time windowProduction correctness outside this scope

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6086

Confirmation

Confirm action

Continue?