Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

SQL Operations

Direct answer

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

When to use this

Use it when writing or reviewing SQL for correctness and safety.

First 30 seconds

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.

Operational verification

statement parsed → planned → executed in a transaction → committed

Evidence · next step

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
Common mistakes
What not to infer

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.

Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts · Databases owns SQL semantics and safe engine-side execution. Automation may deliver migration scripts, but the database Topic remains canonical for what the statements do and how their result is verified.
Scope / prerequisiteUse it when writing or reviewing SQL for correctness and safety.
What next?3 suggested next steps
Child topics (this level)4
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

test · 1
Drill down

Subtopics

Go one level deeper into this subject.

Key points

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).

Key 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
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.

CategoryStatements
QuerySELECT ... FROM ... WHERE ... GROUP BY ... ORDER BY ... LIMIT
Change dataINSERT, UPDATE, DELETE, MERGE/upsert
Define structureCREATE, ALTER, DROP
AccessGRANT, REVOKE
TransactionsBEGIN, 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
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

SQL (PostgreSQL syntax) PostgreSQL 14 or laterChange rows inside a transaction and check the affected count before committing.

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

SQL (PostgreSQL syntax) PostgreSQL 14 or laterUPDATE orders SET status = 'cancelled' WHERE id = 1042 AND status = 'pending';

Expected state: Exactly one row is updated before you commit.

UPDATE 1
UPDATE 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.
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-29 · otherMariaDB / PostgreSQL / Microsoft SQL Server concepts PostgreSQL current documentation

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
sql operationsSQL operationsSELECT INSERT UPDATE DELETEsafe SQL changes
Embedded reference data

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.

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
Depth when you need it

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.

Confirmation

Confirm action

Continue?