sql-database-assistant
What it does
This skill helps write and improve database queries and schema changes. It is for developers and analysts who work with SQL databases day to day.
When to use it
- βWhen you need to write a SQL query from a plain description of what you want.
- βWhen a query is slow and you want to know why and how to speed it up.
- βWhen you need a migration script for a change to your database.
Skill link
https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/sql-database-assistant/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βWrite a SQL query that shows the total sales per customer for last month and make it faster.β
5 new skills a week. 1 minute to read.
How it works
It turns your request into a query, checks existing queries for slow patterns and suggests indexes, and can generate migration files with rollback steps.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
SQL Database Assistant - POWERFUL Tier Skill
Overview
The operational companion to database design. While database-designer focuses on schema architecture and database-schema-designer handles ERD modeling, this skill covers the day-to-day: writing queries, optimizing performance, generating migrations, and bridging the gap between application code and database engines.
Core Capabilities
- Natural Language to SQL β translate requirements into correct, performant queries
- Schema Exploration β introspect live databases across PostgreSQL, MySQL, SQLite, SQL Server
- Query Optimization β EXPLAIN analysis, index recommendations, N+1 detection, rewrite patterns
- Migration Generation β up/down scripts, zero-downtime strategies, rollback plans
- ORM Integration β Prisma, Drizzle, TypeORM, SQLAlchemy patterns and escape hatches
- Multi-Database Support β dialect-aware SQL with compatibility guidance
Tools
| Script | Purpose |
|---|---|
scripts/query_optimizer.py |
Static analysis of SQL queries for performance issues |
scripts/migration_generator.py |
Generate migration file templates from change descriptions |
scripts/schema_explorer.py |
Generate schema documentation from introspection queries |
Natural Language to SQL
Translation Patterns
When converting requirements to SQL, follow this sequence:
- Identify entities β map nouns to tables
- Identify relationships β map verbs to JOINs or subqueries
- Identify filters β map adjectives/conditions to WHERE clauses
- Identify aggregations β map "total", "average", "count" to GROUP BY
- Identify ordering β map "top", "latest", "highest" to ORDER BY + LIMIT
Common Query Templates
Top-N per group (window function)
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rn
FROM employees
) ranked WHERE rn <= 3;
Running totals
SELECT date, amount,
SUM(amount) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total
FROM transactions;
Gap detection
SELECT curr.id, curr.seq_num, prev.seq_num AS prev_seq
FROM records curr
LEFT JOIN records prev ON prev.seq_num = curr.seq_num - 1
WHERE prev.id IS NULL AND curr.seq_num > 1;
UPSERT (PostgreSQL)
INSERT INTO settings (key, value, updated_at)
VALUES ('theme', 'dark', NOW())
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at;
UPSERT (MySQL)
INSERT INTO settings (key_name, value, updated_at)
VALUES ('theme', 'dark', NOW())
ON DUPLICATE KEY UPDATE value = VALUES(value), updated_at = VALUES(updated_at);
See references/query_patterns.md for JOINs, CTEs, window functions, JSON operations, and more.
Schema Exploration
Introspection Queries
PostgreSQL β list tables and columns
SELECT table_name, column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema = 'public'
ORDER BY table_name, ordinal_position;
PostgreSQL β foreign keys
SELECT tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table, ccu.column_name AS foreign_column
FROM information_schema.table_constraints tc
JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage ccu ON tc.constraint_name = ccu.constraint_name
WHERE tc.constraint_type = 'FOREIGN KEY';
MySQL β table sizes
SELECT table_name, table_rows,
ROUND(data_length / 1024 / 1024, 2) AS data_mb,
ROUND(index_length / 1024 / 1024, 2) AS index_mb
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY data_length DESC;
SQLite β schema dump
SELECT name, sql FROM sqlite_master WHERE type = 'table' ORDER BY name;
SQL Server β columns with types
SELECT t.name AS table_name, c.name AS column_name,
ty.name AS data_type, c.max_length, c.is_nullable
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
JOIN sys.types ty ON c.user_type_id = ty.user_type_id
ORDER BY t.name, c.column_id;
Generating Documentation from Schema
Use scripts/schema_explorer.py to produce markdown or JSON documentation:
python scripts/schema_explorer.py --dialect postgres --tables all --format md
python scripts/schema_explorer.py --dialect mysql --tables users,orders --format json --json
FAQ
Which databases does it support?
It works with PostgreSQL, MySQL, SQLite and SQL Server.
Does it work with ORM tools?
Yes, it covers patterns for Prisma, Drizzle, TypeORM and SQLAlchemy.
Can it look at my live database?
It can explore a schema through introspection queries and generate documentation from it.
Details
Original description by the author
Use for writing or optimizing SQL, exploring a schema, generating migrations or working with Prisma, Drizzle, TypeORM or SQLAlchemy. Analyzes queries with query_optimizer.py and schemas with schema_explorer.py.
Popularity
- GitHub stars
- 29k
- Ranking position
- #9606
- License
- MIT
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
agent-launcher-orchestrator
29kHelps your agent plan, build, test and schedule a Claude managed agent in your own account, step by step, starting from one clear goal.
grade-iterate
29kLets your agent grade a managed AI agent's work against a rubric and improve it in a fixed number of rounds, so it never loops forever.
interview
29kLets your agent interview you about an AI agent idea and turn your answers into a simple build plan before anything is launched.
run-without-you
29kHelps your agent set up a managed AI agent to run on a schedule or when an event happens, with the cron timing checked before launch.
Similar skills
discrawl
394kLets your agent search and summarize a saved local archive of Discord messages, check how fresh it is, and read direct messages.
clickhouse-io
280kHelps your agent optimize queries and schemas in ClickHouse databases. It applies best practices for high-performance analytical workloads. Use when analytical queries are too slow.
scientific-db-pubmed-database
280kHelps your agent search for scientific articles in the biomedical field. It's useful for research needing specific medical information.