Agent skill

SQL Pro

by Jeffallan in Jeffallan/claude-skills

Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases.

MITAuto-check passedDatabases

Install SQL Pro

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

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Jeffallan/claude-skills sql-pro --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Jeffallan/claude-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/sql-pro .claude/skills/sql-pro && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
sql-pro
GitHub stars
12k
Token cost
~1.3k tokens
SKILL.md length
299 words
Files
6 (incl. references)
Skills in repo
58
Repo updated
First seen
Licence
MIT

At a glance

Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases.

  • Works in 5 steps: Schema Analysis - Review database… → Design - Create set-based operations… → Optimize - Analyze execution plans,… → …
  • Finding out why a query is slow and rewriting it
  • SKILL.md covers Core Workflow, Reference Guide, Quick-Reference Examples and Constraints, plus 1 more section
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

The agent reviews database structure, indexes and query patterns, writes set-based queries with CTEs, window functions and fitting joins, and reads execution plans to add covering indexes and remove table scans. Verification runs EXPLAIN ANALYZE, checks that large tables avoid sequential scans, and loops back to indexes or rewrites if a query misses the sub-100ms target. Results are documented with query explanations, index rationale and performance numbers.

Reference files cover joins, CTEs, subqueries and recursive queries, window functions such as ROW_NUMBER, RANK, LAG and LEAD, optimization, normalization and constraints, and differences between PostgreSQL, MySQL and SQL Server. The plan-reading advice treats a Seq Scan on a large table as a cue to fix an index and calls for refreshed statistics when actual rows far exceed estimates. A before-and-after example replaces a correlated subquery.

When your agent uses it

  • Finding out why a query is slow and rewriting it
  • Writing complex joins, CTEs, recursive queries or window functions
  • Designing covering indexes from an execution plan
  • Designing or migrating a database schema
  • Porting queries between database dialects such as PostgreSQL, MySQL and SQL Server

Example prompts

  • “This report query takes too long, so read its EXPLAIN ANALYZE output and fix it.”
  • “Write a query that ranks employees by salary within each department and shows a running total.”
  • “Rewrite the correlated subquery in the orders view as a join with aggregation.”
  • “Port these PostgreSQL queries to MySQL and list anything that behaves differently.”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  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…
  5. Document - Provide query explanations, index rationale, performance metrics

What it can do on your machine

Read from SKILL.md and the folder at commit 1be15d8. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • github.com
    • synergetic.solutions
    • jeffallan.github.io

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

SQL Pro loads about 1.3k tokens when it runs, and up to ~14k if it reads all its reference files. Until then it costs about 140 tokens; SKILL.md has 299 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~140
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~14k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Jeffallan/claude-skills at commit 1be15d8, republished under its MIT licence (© Jeffallan). 299 words, ~1,348 tokens.

Download SKILL.mdSave it as .claude/skills/sql-pro/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.
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
metadata.company
https://synergetic.solutions
metadata.version
1.1.0
metadata.domain
language
metadata.triggers
SQL optimization, query performance, database design, PostgreSQL, MySQL, SQL Server, window functions, CTEs, query tuning, EXPLAIN plan, database indexing
metadata.role
specialist
metadata.scope
implementation
metadata.output-format
code
metadata.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:

TopicReferenceLoad When
Query Patternsreferences/query-patterns.mdJOINs, CTEs, subqueries, recursive queries
Window Functionsreferences/window-functions.mdROW_NUMBER, RANK, LAG/LEAD, analytics
Optimizationreferences/optimization.mdEXPLAIN plans, indexes, statistics, tuning
Database Designreferences/database-design.mdNormalization, keys, constraints, schemas
Dialect Differencesreferences/dialect-differences.mdPostgreSQL 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, Principal Consultant at Synergetic Solutions

Documentation

© Jeffallan, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 5 other files (references) in skills/sql-pro of Jeffallan/claude-skills.

  • SKILL.md
  • references/database-design.md
  • references/dialect-differences.md
  • references/optimization.md
  • references/query-patterns.md
  • references/window-functions.md

Open the folder on GitHubat commit 1be15d8

Compare with similar skills

SQL Pro next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

SQL Pro compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
SQL Pro this skillJeffallan/claude-skills12k—~1.3kAutomated safety check: PassMIT
Agent SQL Proxiaoyuge886/aigc198—~315Automated safety check: PassMIT
SQL Expertaiskillstore/marketplace430—~3.4kAutomated safety check: PassNone
SQL Optimizationgithub/awesome-copilot40k2 repos~2.3kAutomated safety check: PassMIT
Optimizing SQLancoleman/ai-design-components526—~3kAutomated safety check: PassMIT
SQL ToolkitLeoYeAI/openclaw-master-skills2.2k—~3kAutomated safety check: PassMIT

Similar skills

  • Agent SQL Pro

    xiaoyuge886/aigc

    Expert SQL developer specializing in complex query optimization, database design, and performance tuning across PostgreSQL, MySQL, SQL Server, and Oracle.

    198 GitHub stars~315 tokensUpdated 2 mo ago
    DatabasesAuto-check passed
  • SQL Expert

    aiskillstore/marketplace

    Expert SQL query writing, optimization, and database schema design with support for PostgreSQL, MySQL, SQLite, and SQL Server.

    430 GitHub stars~3.4k tokensUpdated today
    DatabasesAuto-check passed
  • SQL Optimization

    github/awesome-copilot

    Official

    Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server…

    40k GitHub starsUsed in 2 repos~2.3k tokens
    DatabasesAuto-check passed
  • Optimizing SQL

    ancoleman/ai-design-components

    Optimize SQL query performance through EXPLAIN analysis, indexing strategies, and query rewriting for PostgreSQL, MySQL, and SQL Server.

    526 GitHub stars~3k tokensUpdated 10 mo ago
    DatabasesAuto-check passed
  • SQL Toolkit

    LeoYeAI/openclaw-master-skills

    Query, design, migrate, and optimize SQL databases. An agent skill from LeoYeAI/openclaw-master-skills.

    2.2k GitHub stars~3k tokensUpdated 2 mo ago
    DatabasesAuto-check passed
  • Tsh SQL And Database Understanding

    TheSoftwareHouse/copilot-collections

    SQL writing and database engineering patterns, standards, and procedures.

    284 GitHub stars~11k tokensUpdated 2 days ago
    DatabasesAuto-check passed

More from Jeffallan/claude-skills

All 58 skills in this repo
  • API Designer

    Jeffallan/claude-skills

    Designs REST and GraphQL APIs from resource modeling to an OpenAPI 3.1 contract, with versioning, pagination and RFC 7807 error handling.

    12k GitHub starsUsed in 2 repos~2k tokens
    Auto-check passed
  • CLI Developer

    Jeffallan/claude-skills

    Walks through designing, building and polishing a command-line tool: user workflow and command hierarchy, implementation in commander, click, typer or cobra, completions and cross-platform testing.

    12k GitHub starsUsed in 1 repo~1.2k tokens
    Auto-check passed
  • Fine-Tuning Expert

    Jeffallan/claude-skills

    Guides LLM fine-tuning with LoRA and QLoRA through Hugging Face PEFT, from dataset validation and training checks to adapter merging, quantization and deployment.

    12k GitHub starsUsed in 1 repo~1.7k tokens
    Auto-check passed
  • GraphQL Architect

    Jeffallan/claude-skills

    Designs GraphQL schemas and Apollo Federation graphs, with DataLoader resolvers, subscriptions, query complexity limits and caching.

    12k GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • Kubernetes Specialist

    Jeffallan/claude-skills

    Creates and checks Kubernetes manifests, Helm charts, RBAC and network policies, and helps debug pod problems, with kubectl checks and rollback steps.

    12k GitHub starsUsed in 1 repo~2.1k tokens
    Auto-check passed
  • Laravel Specialist

    Jeffallan/claude-skills

    Builds Laravel 10+ applications with Eloquent models, Sanctum authentication, Horizon queues, API resources and Livewire components, tested with Pest or PHPUnit.

    12k GitHub starsUsed in 1 repo~2.1k tokens
    Auto-check passed

Categories

Questions about SQL Pro

What does SQL Pro do?

Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases. The agent reviews database structure, indexes and query patterns, writes set-based queries with CTEs, window functions and fitting joins, and reads execution plans to add covering indexes and remove table scans. Verification runs EXPLAIN ANALYZE, checks that large tables avoid sequential scans, and loops back to indexes or rewrites if a query misses the sub-100ms target.

When should I use SQL Pro?

SQL Pro fits situations like: finding out why a query is slow and rewriting it; writing complex joins, CTEs, recursive queries or window functions; designing covering indexes from an execution plan; designing or migrating a database schema.

How do I install SQL Pro in Claude Code?

Run `npx skills add Jeffallan/claude-skills --skill sql-pro -a claude-code`. Or copy the skill folder (skills/sql-pro in Jeffallan/claude-skills) into .claude/skills/sql-pro in your project. Claude Code loads it when a task matches its description.

How do I install SQL Pro in Codex?

Run `npx skills add Jeffallan/claude-skills --skill sql-pro -a codex`. Or copy the skill folder (skills/sql-pro in Jeffallan/claude-skills) into .agents/skills/sql-pro in your project. Codex loads it when a task matches its description.

Can I use SQL Pro in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Jeffallan/claude-skills --skill sql-pro -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/sql-pro, .gemini/skills/sql-pro, .github/skills/sql-pro and .opencode/skills/sql-pro in your project.

What does SQL Pro need to run?

SKILL.md names no scripts, command-line tools or credentials: SQL Pro is instructions for the agent only.

Does SQL Pro access the network?

SKILL.md names 3 domains. As links in the text: github.com, synergetic.solutions and jeffallan.github.io. This is read from the text; nothing was executed.

Is SQL Pro safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does SQL Pro use?

SQL Pro is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does SQL Pro use?

About 1.3k tokens (SKILL.md is roughly 5.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 13k tokens, read only when the agent opens those files.

What are the alternatives to SQL Pro?

Skills that share tags, products or a category with SQL Pro: Agent SQL Pro (xiaoyuge886/aigc, 198 stars), SQL Expert (aiskillstore/marketplace, 430 stars), SQL Optimization (github/awesome-copilot, 40k stars) and Optimizing SQL (ancoleman/ai-design-components, 526 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains SQL Pro?

Jeffallan (a GitHub user) maintains it in Jeffallan/claude-skills, which has 11,754 GitHub stars. The repository holds 58 skills in this directory. The repository was last updated on October 3, 2026.

Source: Jeffallan/claude-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.