Skip to content
Skillpedia
Databases29k Β· #9606

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

Copy 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

Use this skill to help me: https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/sql-database-assistant/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

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:

  1. Identify entities β€” map nouns to tables
  2. Identify relationships β€” map verbs to JOINs or subqueries
  3. Identify filters β€” map adjectives/conditions to WHERE clauses
  4. Identify aggregations β€” map "total", "average", "count" to GROUP BY
  5. 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.

repo: alirezarezvani/claude-skills

Popularity

GitHub stars
29k
Ranking position
#9606
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills