Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

sql-pro — Claude Code skill: what it does, how to install

Optimizes slow SQL queries, designs database schemas, and fixes performance bottlenecks. Built for EXPLAIN plan tuning and cross-dialect migrations.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Jeffallan/claude-skills --skill sql-pro -a claude-code
Open on GitHub

What sql-pro does

The skill guides query tuning and database schema design through strict set-based patterns. It restructures correlated subqueries using CTEs or window functions, suggests covering indexes, and interprets EXPLAIN (ANALYZE, BUFFERS) output. Supported database engines include PostgreSQL, MySQL, SQL Server, and Oracle.

The core workflow follows five stages: schema analysis, set-based design, execution plan optimization, verification, and documentation. It enforces explicit rules. The agent must replace COUNT with EXISTS, filter before joins, and avoid SELECT * or row-by-row cursors in production code.

Verification requires eliminating sequential scans on large tables and aiming for a sub-100ms runtime. If a query misses that latency target, the skill iterates on index selection or query rewrites before finishing.

What it helps with

  • Rewrite slow correlated subqueries into set-based joins
  • Interpret EXPLAIN ANALYZE output to eliminate sequential scans
  • Design covering indexes for high-frequency queries
  • Migrate SQL queries across PostgreSQL, MySQL, and Oracle

Example prompts for the agent

  • Analyze why this query is slow using this EXPLAIN (ANALYZE, BUFFERS) plan
  • Rewrite this correlated subquery with CTEs and suggest a covering index
  • Convert this PostgreSQL window function query to run on SQL Server

How to install sql-pro

1Skills CLI (Vercel)

npx skills add Jeffallan/claude-skills --skill sql-pro -a claude-code

2Manually: put the files in place

~/.claude/skills/sql-pro/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/sql-pro/

From the same set61

The whole set →
laravel-specialist https://github.com/Jeffallan Configures the agent for Laravel 10+ and PHP 8.2+ development. It guides Eloquent modeling, Horizon queues, API resources, and Pest testing. Claude Code CX Codex Cursor +1 23,300installs golang-pro https://github.com/Jeffallan A Go skill for concurrent code, microservices, performance profiling, and idiomatic interfaces. Use it for goroutines, gRPC, benchmarks, and table-driven tests. Claude Code CX Codex Cursor +1 18,900installs php-pro https://github.com/Jeffallan Enforces PHP 8.3+ standards across Laravel and Symfony projects with strict typing, PHPStan level 9 checks, and automated Pest tests. Claude Code CX Codex Cursor +1 15,500installs flutter-expert https://github.com/Jeffallan Skill for building cross-platform apps with Flutter 3+ and Dart. Covers widgets, state management via Riverpod or Bloc, GoRouter navigation, and performance optimization. Claude Code CX Codex Cursor +1 14,300installs typescript-pro https://github.com/Jeffallan Implements advanced TypeScript type systems, branded types, and tRPC configurations. Use it when building type-first APIs or complex discriminated unions. Claude Code CX Codex Cursor +1 14,200installs kubernetes-specialist https://github.com/Jeffallan This skill helps create and validate Kubernetes manifests, set workload security, and troubleshoot failing pods. Use it for deployment and cluster operations. Claude Code CX Codex Cursor +1 14,100installs devops-engineer https://github.com/Jeffallan This skill creates Dockerfiles, CI/CD configs, Kubernetes manifests, and IaC templates. Use it for deployments, platform work, and incident response. Claude Code CX Codex Cursor +1 11,200installs wordpress-pro https://github.com/Jeffallan This skill builds WordPress themes, plugins, Gutenberg blocks, and WooCommerce features. Use it for REST API work, hooks, security checks, and performance tuning. Claude Code CX Codex Cursor +1 9,700installs

Similar

minimax-xlsx MiniMax-AI Skill to create, read, edit, and validate Excel files (.xlsx, .xlsm, .csv, .tsv) directly in code. Use it when you need to build a financial model, add calculated columns, or fix broken formulas while preserving formatting and macros. Claude Code CX Codex Cursor +1 3,800installs bigquery-observability official google This skill helps retrieve BigQuery telemetry and choose the right data source. Use it to inspect jobs, slot contention, queues, reservations, and resource usage. Claude Code Gemini CLI CX Codex 1,800installs spring-boot-testing official github Helps choose a testing approach for Spring Boot 4, from a focused slice to a full application test. Use it when deciding which annotations and tools fit a test. GitHub Copilot 2,000installs sentiment-analysis phuryn Analyzes user feedback from surveys and reviews to extract customer segments. Computes sentiment scores from -1 to +1 and maps core jobs via JTBD. Claude Code CX Codex Cursor +1 3,100installs metrics-dashboard phuryn A skill that helps you design a product metrics dashboard with North Star Metric, Input Metrics, Health Metrics, and Business Metrics. Use it when defining KPIs, setting up product analytics, or building a data monitoring plan. Claude Code CX Codex Cursor +1 3,000installs xlsx official anthropics Creates, reads, edits, and converts spreadsheet files. Use it when the requested deliverable is an Excel workbook or another tabular file. Claude Code Claude.ai 187,223installs google-agents-cli-observability official Google This skill guides you through tracing and monitoring AI agents, including ADK agents. Use it when you need to inspect agent execution or monitor a deployed agent. Claude Code CX Codex Cursor +1 509,900installs caveman-evidence-review JuliusBrussee A read-only skill reviews Caveman Cloud evidence on LLM spend, traces, and routing. Use it to see where a project’s model budget goes. Claude Code CX Codex Cursor +1 103,500installs

Questions about sql-pro

How to install sql-pro in Claude Code?

Run npx skills add Jeffallan/claude-skills --skill sql-pro -a claude-code in your terminal, or place the skill definition file at ~/.claude/skills/sql-pro/SKILL.md.

What does sql-pro do?

It diagnoses slow queries, analyzes execution plans, creates covering indexes, and optimizes SQL code across multiple database dialects.

Which database dialects are supported?

The skill provides rules and optimizations specifically tailored for PostgreSQL, MySQL, SQL Server, and Oracle.

Source text

SKILL.md · MIT
---
name: sql-pro
description: Optimizes SQL queries, designs database schemas, and troubleshoots performance issues. Use when a user asks why their query is slow, needs help writing complex joins or aggregations, mentions database performance issues, or wants to design or migrate a schema. Invoke for complex queries, window functions, CTEs, indexing strategies, query plan analysis, covering index creation, recursive queries, EXPLAIN/ANALYZE interpretation, before/after query benchmarking, or migrating queries between database dialects (PostgreSQL, MySQL, SQL Server, Oracle).
license: MIT
metadata:
  author: https://github.com/Jeffallan
  company: https://synergetic.solutions
  version: "1.1.0"
  domain: language
  triggers: SQL optimization, query performance, database design, PostgreSQL, MySQL, SQL Server, window functions, CTEs, query tuning, EXPLAIN plan, database indexing
  role: specialist
  scope: implementation
  output-format: code
  related-skills: devops-engineer
---

# SQL Pro

## Core Workflow

1. **Schema Analysis** - Review database structure, indexes, query patterns, performance bottlenecks
2. **Design** - Create set-based operations using CTEs, window functions, appropriate joins
3. **Optimize** - Analyze execution plans, implement covering indexes, eliminate table scans
4. **Verify** - Run `EXPLAIN ANALYZE` and confirm no sequential scans on large tables; if query does not meet sub-100ms target, iterate on index selection or query rewrite before proceeding
5. **Document** - Provide query explanations, index rationale, performance metrics

## Reference Guide

Load detailed guidance based on context:

| Topic | Reference | Load When |
|-------|-----------|-----------|
| Query Patterns | `references/query-patterns.md` | JOINs, CTEs, subqueries, recursive queries |
| Window Functions | `references/window-functions.md` | ROW_NUMBER, RANK, LAG/LEAD, analytics |
| Optimization | `references/optimization.md` | EXPLAIN plans, indexes, statistics, tuning |
| Database Design | `references/database-design.md` | Normalization, keys, constraints, schemas |
| Dialect Differences | `references/dialect-differences.md` | PostgreSQL vs MySQL vs SQL Server specifics |

## Quick-Reference Examples

### CTE Pattern
```sql
-- Isolate expensive subquery logic for reuse and readability
WITH ranked_orders AS (
    SELECT
        customer_id,
        order_id,
        total_amount,
        ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) AS rn
    FROM orders
    WHERE status = 'completed'          -- filter early, before the join
)
SELECT customer_id, order_id, total_amount
FROM ranked_orders
WHERE rn = 1;                           -- latest completed order per customer
```

### Window Function Pattern
```sql
-- Running total and rank within partition — no self-join required
SELECT
    department_id,
    employee_id,
    salary,
    SUM(salary)  OVER (PARTITION BY department_id ORDER BY hire_date) AS running_payroll,
    RANK()       OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank
FROM employees;
```

### EXPLAIN ANALYZE Interpretation
```sql
-- PostgreSQL: always use ANALYZE to see actual row counts vs. estimates
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT *
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.created_at > NOW() - INTERVAL '30 days';
```
Key things to check in the output:
- **Seq Scan on large table** → add or fix an index
- **actual rows ≫ estimated rows** → run `ANALYZE <table>` to refresh statistics
- **Buffers: shared hit** vs **read** → high `read` count signals missing cache / index

### Before / After Optimization Example
```sql
-- BEFORE: correlated subquery, one execution per row (slow)
SELECT order_id,
       (SELECT SUM(quantity) FROM order_items oi WHERE oi.order_id = o.id) AS item_count
FROM orders o;

-- AFTER: single aggregation join (fast)
SELECT o.order_id, COALESCE(agg.item_count, 0) AS item_count
FROM orders o
LEFT JOIN (
    SELECT order_id, SUM(quantity) AS item_count
    FROM order_items
    GROUP BY order_id
) agg ON agg.order_id = o.id;

-- Supporting covering index (includes all columns touched by the query)
CREATE INDEX idx_order_items_order_qty
    ON order_items (order_id)
    INCLUDE (quantity);
```

## Constraints

### MUST DO
- Analyze execution plans before recommending optimizations
- Use set-based operations over row-by-row processing
- Apply filtering early in query execution (before joins where possible)
- Use EXISTS over COUNT for existence checks
- Handle NULLs explicitly in comparisons and aggregations
- Create covering indexes for frequent queries
- Test with production-scale data volumes

### MUST NOT DO
- Use SELECT * in production queries
- Use cursors when set-based operations work
- Ignore platform-specific optimizations when targeting a specific dialect
- Implement solutions without considering data volume and cardinality

## Output Templates

When implementing SQL solutions, provide:
1. Optimized query with inline comments
2. Required indexes with rationale
3. Execution plan analysis
4. Performance metrics (before/after)
5. Platform-specific notes if applicable

Maintained by [@jeffallan](https://github.com/jeffallan), Principal Consultant at [Synergetic Solutions](https://synergetic.solutions)

[Documentation](https://jeffallan.github.io/claude-skills/skills/language/sql-pro/)

© https://github.com/Jeffallan · MIT · Jeffallan/claude-skills

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor