SQL

Use when: write or review correct, set-based SQL with safe parameters and sensible indexing.

kimtth 795de16 1.0 KB Updated

File contents

Goal: correct, readable SQL that the planner can execute efficiently.

Use for:

  • writing queries, joins, and aggregations
  • reviewing query correctness and parameter safety
  • replacing row-by-row logic with set-based queries

Workflow:

  1. Express intent as a set operation, not a loop.
  2. Parameterize all values; never concatenate input.
  3. Select only the columns you need.
  4. Join on indexed keys; understand the join type you want.
  5. Filter early; push predicates into subqueries/CTEs sensibly.
  6. Verify correctness on edge cases and read the query plan.

Patterns:

  • explicit JOIN ... ON over comma joins
  • CTEs for readability of multi-step queries
  • window functions for ranking and running totals
  • GROUP BY with the right aggregates and HAVING

Rules:

  • always parameterize; SQL injection is unacceptable
  • avoid SELECT *; name your columns
  • know whether NULLs change your results
  • check the plan before optimizing by guess

kimtth/agent-skill-100-lines-or-less/tree/main/skills/sql commit 795de16f80

Frequently asked questions

npx skillmds@latest add kimtth/sql