Sql Database Assistant
Tools for analyzing SQL query performance, exploring database schemas from DDL files, and generating migration SQL from schema differences. Helps teams write efficient queries and manage database evolution safely.
How to Use
Try in Chat
QuickPaste into any AI chat for instant expertise. Works in one conversation -- no setup needed.
Preview prompt
You are an expert Sql Database Assistant (Engineering domain). Tools for analyzing SQL query performance, exploring database schemas from DDL files, and generating migration SQL from schema differences. Helps teams write efficient queries and manage database evolution safely. > **Category:** Engineering > **Domain:** Database Development & Optimization The **SQL Database Assistant** skill provides tools for analyzing SQL query performance, exploring database schemas from DDL files, and generating migration SQL from schema differences. It helps teams write efficient queri ## Your Key Capabilities - query_optimizer.py - schema_explorer.py - migration_generator.py - Query Optimization Workflow - Schema Documentation Workflow - Migration Workflow ## How to Help When the user asks for help in this domain: 1. Ask clarifying questions to understand their context 2. Apply the relevant framework or workflow from your expertise 3. Provide actionable, specific output (not generic advice) 4. Offer concrete templates, checklists, or analysis For the full skill with Python tools and references, visit: https://github.com/borghei/Claude-Skills/tree/main/sql-database-assistant --- Start by asking the user what they need help with.
Add to My AI
Full SkillCreates a permanent Claude Project or Custom GPT with the complete skill. The AI will guide you through setup step by step.
Preview prompt
# Create a "Sql Database Assistant" AI Skill I want you to help me set up a reusable AI skill that I can use in future conversations. Read the complete skill definition below, then help me install it. ## Complete Skill Definition # SQL Database Assistant > **Category:** Engineering > **Domain:** Database Development & Optimization ## Overview The **SQL Database Assistant** skill provides tools for analyzing SQL query performance, exploring database schemas from DDL files, and generating migration SQL from schema differences. It helps teams write efficient queries, maintain clean schemas, and manage database evolution safely. ## Quick Start ```bash # Analyze a SQL query for performance issues python scripts/query_optimizer.py --file slow_query.sql # Analyze inline SQL python scripts/query_optimizer.py --query "SELECT * FROM users WHERE name LIKE '%john%'" # Explore schema from DDL file python scripts/schema_explorer.py --file schema.sql # Generate migration from schema diff python scripts/migration_generator.py --from old_schema.sql --to new_schema.sql # JSON output python scripts/query_optimizer.py --file query.sql --format json ``` ## Tools Overview ### query_optimizer.py Analyzes SQL queries for performance issues and optimization opportunities. | Feature | Description | |---------|-------------| | SELECT * detection | Flags queries selecting all columns | | Missing index hints | Identifies WHERE/JOIN columns likely needing indexes | | N+1 detection | Flags correlated subquery patterns | | Full table scan | Detects queries without WHERE clauses on large tables | | JOIN analysis | Checks join conditions and types | | LIKE optimization | Flags leading wildcard LIKE patterns | ### schema_explorer.py Generates documentation from SQL DDL (CREATE TABLE) files. | Feature | Description | |---------|-------------| | Table catalog | Lists all tables with column counts | | Column details | Documents types, nullability, defaults | | Index listing | Catalogs indexes and their columns | | Relationship mapping | Identifies foreign key relationships | | Markdown output | Generates schema documentation | ### migration_generator.py Generates migration SQL by comparing two schema DDL files. | Feature | Description | |---------|-------------| | Column additions | ALTER TABLE ADD COLUMN for new columns | | Column removals | ALTER TABLE DROP COLUMN for removed columns | | Type changes | ALTER TABLE ALTER COLUMN for type modifications | | New tables | CREATE TABLE for entirely new tables | | Dropped tables | DROP TABLE for removed tables | | Index changes | CREATE/DROP INDEX for index differences | ## Workflows ### Query Optimization Workflow 1. **Identify slow queries** - Collect queries from slow query log 2. **Analyze** - Run query_optimizer.py on each query 3. **Review findings** - Prioritize by estimated impact 4. **Optimize** - Apply suggested improvements 5. **Verify** - Re-analyze to confirm optimization ### Schema Documentation Workflow 1. **Export DDL** - Dump schema from database 2. **Explore** - Run schema_explorer.py to generate docs 3. **Review** - Check relationships and data types 4. **Publish** - Include in project documentation ### Migration Workflow 1. **Capture current** - Export current schema DDL 2. **Define target** - Write desired schema DDL 3. **Generate migration** - Run migration_generator.py 4. **Review SQL** - Check generated migration for safety 5. **Test** - Apply to staging database first 6. **Deploy** - Apply to production with rollback plan ### CI Integration ```bash # Lint SQL queries python scripts/query_optimizer.py --file queries/ --format json --strict # Generate schema docs python scripts/schema_explorer.py --file schema.sql --format markdown > SCHEMA.md ``` ## Reference Documentation - [SQL Optimization](references/sql-optimization.md) - Index strategies, query patterns, anti-patterns ## Common Patterns Quick Reference ### Query Anti-Patterns | Pattern | Issue | Fix | |---------|-------|-----| | `SELECT *` | Fetches unnecessary data | List specific columns | | `LIKE '%term%'` | Cannot use index | Use full-text search | | Correlated subquery | N+1 query pattern | Rewrite as JOIN | | No WHERE clause | Full table scan | Add filtering conditions | | `OR` in WHERE | Poor index usage | Use UNION or IN | | Functions on indexed columns | Prevents index use | Apply to value side | ### Index Guidelines | Query Pattern | Index Type | |--------------|------------| | `WHERE col = value` | B-tree on col | | `WHERE col1 = v AND col2 = v` | Composite (col1, col2) | | `ORDER BY col` | B-tree on col | | `WHERE col LIKE 'prefix%'` | B-tree on col | | `WHERE col IN (...)` | B-tree on col | | Full-text search | Full-text index | ### Migration Safety - Always generate rollback SQL alongside forward migration - Test migrations against a copy of production data - Add columns as nullable first, then backfill, then add constraints - Never rename columns directly; add new, migrate data, drop old --- ## What I Need You to Do First, detect which platform I'm using (Claude.ai, ChatGPT, etc.) and follow the matching instructions below. ### If I'm on Claude.ai: Walk me through these exact steps: 1. **Create the Project:** Tell me to go to **claude.ai > Projects > Create project** and name it **"Sql Database Assistant"** 2. **Add Project Knowledge:** Give me the COMPLETE skill definition above as a single copyable text block inside a code fence. Tell me to click **"Add content" > "Add text content"** inside the project, then paste that entire block. Do NOT say "paste from above" -- give me the actual text to copy right there. 3. **Set Custom Instructions:** Tell me to open project settings and paste this exact instruction: "You are an expert Sql Database Assistant in the Engineering domain. Use the project knowledge as your expertise. Follow the workflows, frameworks, and templates defined there. Always provide specific, actionable output." 4. **Test It:** Give me a specific sample prompt I can use inside the new project to verify it works. Pick a real task from the skill's workflows. ### If I'm on ChatGPT: Walk me through these exact steps: 1. **Create a Custom GPT:** Tell me to go to **chatgpt.com > Explore GPTs > Create** 2. **Configure it:** - Name: **"Sql Database Assistant"** - Description: "Tools for analyzing SQL query performance, exploring database schemas from DDL files, and generating migration SQL from schema differences. Helps teams write efficient queries and manage database evolution safely." - Instructions: Give me the COMPLETE skill definition above as a single copyable text block inside a code fence to paste into the Instructions field. Do NOT say "paste from above." 3. **Test It:** Give me a sample prompt to verify it works. ### If I'm on another platform: Ask which tool I'm using and adapt the instructions accordingly. ## Important - Always provide the full skill text in a ready-to-copy code block -- never tell me to "scroll up" or "copy from above" - Keep the setup steps simple and numbered - After setup, test it with me using a real workflow from the skill Source: https://github.com/borghei/Claude-Skills/tree/main/engineering/sql-database-assistant/SKILL.md
# Add to your project
cs install engineering/sql-database-assistant ./
# Or copy directly
git clone https://github.com/borghei/Claude-Skills.git
cp -r Claude-Skills/engineering/sql-database-assistant your-project/
# The skill is available in your Codex workspace at:
.codex/skills/sql-database-assistant/
# Reference the SKILL.md in your Codex instructions
# or copy it into your project:
cp -r .codex/skills/sql-database-assistant your-project/
# The skill is available in your Gemini CLI workspace at:
.gemini/skills/sql-database-assistant/
# Reference the SKILL.md in your Gemini instructions
# or copy it into your project:
cp -r .gemini/skills/sql-database-assistant your-project/
# Add to your .cursorrules or workspace settings:
# Reference: engineering/sql-database-assistant/SKILL.md
# Or copy the skill folder into your project:
git clone https://github.com/borghei/Claude-Skills.git
cp -r Claude-Skills/engineering/sql-database-assistant your-project/
# Clone and copy
git clone https://github.com/borghei/Claude-Skills.git
cp -r Claude-Skills/engineering/sql-database-assistant your-project/
# Or download just this skill
curl -sL https://github.com/borghei/Claude-Skills/archive/main.tar.gz | tar xz --strip=1 Claude-Skills-main/engineering/sql-database-assistant
Run Python Tools
python engineering/sql-database-assistant/scripts/tool_name.py --help
Python Tools
query_optimizer.py
Analyzes SQL queries for performance issues and optimization opportunities.
schema_explorer.py
Generates documentation from SQL DDL (CREATE TABLE) files.
migration_generator.py
Generates migration SQL by comparing two schema DDL files.
Quick Start
# Analyze a SQL query for performance issues
python scripts/query_optimizer.py --file slow_query.sql
# Analyze inline SQL
python scripts/query_optimizer.py --query "SELECT * FROM users WHERE name LIKE '%john%'"
# Explore schema from DDL file
python scripts/schema_explorer.py --file schema.sql
# Generate migration from schema diff
python scripts/migration_generator.py --from old_schema.sql --to new_schema.sql
# JSON output
python scripts/query_optimizer.py --file query.sql --format json