본문으로 건너뛰기
Skillpedia
데이터베이스12k · #11460

sql-pro

하는 일

복잡한 SQL을 작성하고, 데이터베이스 구조를 계획하며, 느린 쿼리를 빠르게 하도록 AI 에이전트를 안내합니다. 데이터베이스로 일하는 개발자와 분석가를 위한 스킬입니다.

사용하는 경우

  • ✓데이터베이스 쿼리가 느려서 이유를 알고 싶을 때.
  • ✓조인, 윈도우 함수, 재귀 쿼리를 작성하는 데 도움이 필요할 때.
  • ✓새 데이터베이스 스키마나 새 테이블 구조로 옮기는 계획을 세울 때.

스킬 링크

https://github.com/Jeffallan/claude-skills/blob/main/skills/sql-pro/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/Jeffallan/claude-skills/blob/main/skills/sql-pro/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 SQL 쿼리가 왜 10초나 걸리나요? 어떻게 하면 더 빠르게 만들 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

AI는 테이블과 인덱스를 검토하고, 쿼리를 다시 작성한 뒤, 쿼리 계획을 확인해 전체 테이블 스캔을 피했는지 점검합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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

-- 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

-- 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

-- 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

-- 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

자주 묻는 질문

어떤 데이터베이스를 다루나요?

PostgreSQL, MySQL, SQL Server의 차이를 설명하므로 여러 흔한 데이터베이스를 다룹니다.

내 데이터베이스에 접근해야 하나요?

쿼리 계획을 확인하려면 EXPLAIN ANALYZE를 실행하라고 제안하며, 이때 데이터베이스에서 쿼리를 실행할 권한이 필요합니다.

테이블 설계도 도와줄 수 있나요?

네. 정규화, 키, 제약 조건, 스키마 설계를 다룹니다.

상세 정보

작성자의 원본 설명

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).

repo: Jeffallan/claude-skills

인기도

GitHub 스타
12k
순위
#11460
라이선스
MIT
업데이트
2026. 10. 30.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬