Skip to content

Skill: Structured SQL Review

Skill: Structured SQL Review

Context

This is a Claude Code slash-command skill (.claude/commands/review-sql.md) that performs a structured review of SQL code covering four categories: logic errors, data quality risks, performance concerns, and readability. Each finding includes what the issue is, exactly where it appears, and what the fix is. The review ends with a summary verdict: APPROVED, NEEDS CHANGES, or BLOCKED.

Install this skill in your project and invoke it with /review-sql [paste SQL here] to get an immediate structured review without leaving your build-cli session.

The Prompt

Review the following SQL. Provide a structured assessment covering:
1. **Logic errors** — does the SQL do what it's supposed to do? Check GROUP BY completeness, join conditions, aggregation logic.
2. **Data quality risks** — null handling on join keys, potential duplicates, fan-out joins, type mismatches.
3. **Performance concerns** — missing filters, Cartesian products, unnecessary subqueries, missing partition pruning.
4. **Readability** — unclear aliases, missing CTEs for complex logic, inconsistent style.
For each finding, state: what the issue is, where exactly it appears, and what the fix is.
End with a summary: APPROVED / NEEDS CHANGES / BLOCKED, with one sentence of justification.
$ARGUMENTS

How to Install as a Claude Code Slash-Command

  1. Copy the prompt text above (the content between the triple backticks, including $ARGUMENTS).
  2. Create the file .claude/commands/review-sql.md in your project root (or ~/.claude/commands/review-sql.md for global use).
  3. Paste the prompt text as the entire file content.
  4. The $ARGUMENTS token is replaced by Claude Code with whatever SQL you paste after the slash-command.

Usage Instructions

Once installed, invoke the skill in a build-cli session:

/review-sql SELECT c.customer_id, o.total_amount FROM customers c JOIN orders o ON c.id = o.customer_id WHERE o.status = 'COMPLETE'

Claude Code will produce a structured review across all four categories, with specific findings and fixes. The summary verdict (APPROVED / NEEDS CHANGES / BLOCKED) gives you a clear action signal.

Tip: For long SQL queries, paste the SQL directly into a new file, open build-cli in that directory, and invoke /review-sql with the file contents. The skill works on any SQL dialect — specify the dialect in the SQL comments if dialect-specific behaviour matters.