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.
$ARGUMENTSHow to Install as a Claude Code Slash-Command
- Copy the prompt text above (the content between the triple backticks, including
$ARGUMENTS). - Create the file
.claude/commands/review-sql.mdin your project root (or~/.claude/commands/review-sql.mdfor global use). - Paste the prompt text as the entire file content.
- The
$ARGUMENTStoken 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.