Skills

SQL Insight

Translate natural language to SQL, optimize query performance, and interpret EXPLAIN...

Install

npx skills add zebbern/claude-code-guide --skill sql-insight -g -a claude-code -y
Category
Data and ML
Updated
4d ago
License
MIT
Context cost
Mediumabout 2,017 tokens
Runs scripts
Yes, review before use

What it does

Translate natural language to SQL, optimize query performance, and interpret EXPLAIN plans for SQLite and PostgreSQL. Triggered when users ask to convert questions into SQL, improve slow queries, tune indexes, analyze execution plans, or mention keywords like NL2SQL, query tuning, or full table scan.

sql-insight

SQL query assistant, natural language to SQL translation, query optimization analysis, and EXPLAIN plan interpretation.

Capabilities

FeatureDescription
Schema ExtractionExtracts database table structure (columns, types, indexes, foreign keys, sample data) to provide context for NL→SQL
Natural Language → SQLTranslates natural language descriptions into SQL queries using schema context
Query Optimization AnalysisDetects SQL anti-patterns based on 13 rules and provides optimization suggestions
EXPLAIN InterpretationRuns EXPLAIN and interprets the query plan, identifying full table scans, missing indexes, and more

Workflow

Natural Language → SQL

  1. Use the schema command to extract the database table structure
  2. Use the schema as context to translate the user's natural language request into SQL
  3. Use the optimize command to check if the generated SQL can be improved
  4. Use the explain command to verify the query execution plan
# Step 1: Extract schema (compact mode, suitable for LLM context)
python3 scripts/sql_query_helper.py --db-path data.db schema --compact

# Step 2: Analyze SQL optimization suggestions
python3 scripts/sql_query_helper.py optimize "SELECT * FROM orders WHERE user_id = 100"

# Step 3: View EXPLAIN execution plan
python3 scripts/sql_query_helper.py --db-path data.db explain "SELECT * FROM orders WHERE user_id = 100"

Quick Start

Schema Extraction

# Extract full schema (JSON format, with sample data)
python3 scripts/sql_query_helper.py --db-path data.db schema

# Compact mode (plain text, suitable for embedding in prompts)
python3 scripts/sql_query_helper.py --db-path data.db schema --compact

# Skip data sampling
python3 scripts/sql_query_helper.py --db-path data.db schema --sample-rows 0
Read the whole SKILL.md on GitHub

More in Data and ML