Use it when writing or reviewing SQL for correctness and safety.
SQL Operations
SQL operations read and change data: SELECT, INSERT, UPDATE, DELETE, plus DDL (CREATE, ALTER) and transaction control (BEGIN, COMMIT, ROLLBACK).
1. Write the WHERE clause as a SELECT count(*) … WHERE … first.
2. BEGIN; run the change, check rows affected.
3. COMMIT; or ROLLBACK;.
4. DDL on big tables → check locking behaviour.
5. Parameterised queries in code.
statement parsed → planned → executed in a transaction → committed
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. Preserve the first divergent observation and repeat the same bounded verification after remediation.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
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.
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification workflow Verify boundary
Before a production mutation, confirm database/schema, predicate and expected row count using a read-only query where possible. Use a transaction when supported/appropriate, capture the actual affected-row/result state, and verify application-visible data afterward.
Step 2 Failure signatures and limits Narrow the fault
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.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
SELECT reads rows from one or more tables; WHERE filters rows, ORDER BY sorts and LIMIT caps the result.
Subtopic JOINsJOINs combine rows from two tables on a matching condition; INNER returns only matches, LEFT keeps all rows from the left table.
Subtopic INSERT, UPDATE and DELETE SafelyData-changing statements should run in a transaction with a tested WHERE clause and a known expected row count.
Subtopic GROUP BY and AggregatesGROUP BY collapses rows that share values into groups so aggregate functions such as count, sum and avg can be computed per group.
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).
SELECT count(*) … WHERE …— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
Operating model
SQL Operations covers the core statements used to read and mutate relational data and schema. The operational emphasis is scope control: know which rows/objects a statement can affect, understand transaction boundaries, inspect plans for expensive reads, and keep destructive DDL/DML changes reviewable and recoverable.
ReferenceHow it works1 section · depth on demand
In depth
SQL operations cover the statements used to read and change data (DML), define structures (DDL) and control access (DCL), plus the transaction commands that group changes safely.
| Category | Statements |
|---|---|
| Query | SELECT ... FROM ... WHERE ... GROUP BY ... ORDER BY ... LIMIT |
| Change data | INSERT, UPDATE, DELETE, MERGE/upsert |
| Define structure | CREATE, ALTER, DROP |
| Access | GRANT, REVOKE |
| Transactions | BEGIN, COMMIT, ROLLBACK, SAVEPOINT |
Safe habits for changes in production:
BEGIN;
SELECT count(*) FROM devices WHERE site = 'oslo' AND status = 'retired'; -- check scope first
UPDATE devices SET status = 'archived' WHERE site = 'oslo' AND status = 'retired';
-- verify the reported row count matches, then:
COMMIT; -- or ROLLBACK;
Always run the matching SELECT before an UPDATE or DELETE, use transactions, and be careful with tools that auto-commit each statement.
ReferenceImportant terms & boundaries1 section · depth on demand
Scope map
- SELECT
- INSERT / UPDATE / DELETE
- JOINs
- Filtering and aggregation
- DDL basics
- Safe production-change boundaries
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Table orders exists. Replace table, predicate and values.
BEGIN;
UPDATE orders SET status = 'cancelled'
WHERE id = 1042 AND status = 'pending';
-- expect: UPDATE 1
SELECT id, status FROM orders WHERE id = 1042;
COMMIT; -- or ROLLBACK;Expected output
UPDATE orders SET status = 'cancelled' WHERE id = 1042 AND status = 'pending';Expected state: Exactly one row is updated before you commit.
UPDATE 1UPDATE 0 means the predicate matched nothing (wrong id or status already changed); a larger count means the WHERE clause is too broad. Roll back in both cases. Illustrative authored output: field layout matches the tool, values will differ in your environment.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Documentation verification: confirms the upstream model used by the Topic. It does not assert local production behavior.
Basis: https://www.postgresql.org/docs/current/sql-commands.html · confidence 92%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
SQL Operations verification boundary matrix
A compact lookup separating intent, owning component state, effective state and consumer-visible outcome for SQL Operations.
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | SELECT | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | INSERT / UPDATE / DELETE / JOINs | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Filtering and aggregation | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | DDL basics | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Deep reference
Design & tradeoffs
Scope
Automation may deliver migration scripts, but the database Topic remains canonical for what the statements do and how their result is verified.