
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- Repository
- zebbern/claude-code-guide4.7k
- 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
| Feature | Description |
|---|---|
| Schema Extraction | Extracts database table structure (columns, types, indexes, foreign keys, sample data) to provide context for NL→SQL |
| Natural Language → SQL | Translates natural language descriptions into SQL queries using schema context |
| Query Optimization Analysis | Detects SQL anti-patterns based on 13 rules and provides optimization suggestions |
| EXPLAIN Interpretation | Runs EXPLAIN and interprets the query plan, identifying full table scans, missing indexes, and more |
Workflow
Natural Language → SQL
- Use the
schemacommand to extract the database table structure - Use the schema as context to translate the user's natural language request into SQL
- Use the
optimizecommand to check if the generated SQL can be improved - Use the
explaincommand 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
