SQL
Writes, reviews, and optimizes SQL queries; designs schemas, indexes, and constraints; plans migrations for any relational database. Use when a query is slow…
от clawic★ 23 звезды на GitHub
Установить SQL в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
User preferences and memory live in ~/Clawic/data/sql/ (see setup.md on first use, memory-template.md for the file format). If you have data at an old location (~/sql/ or ~/clawic/sql/), move it to ~/Clawic/data/sql/, and say in one line that you moved it and from where.
When To Use
- Writing, reviewing, or optimizing SQL: queries, joins, CTEs, window functions, upserts
- Designing tables, keys, types, indexes, and constraints, or normalizing an existing model
- Diagnosing a slow query, a deadlock, a lock timeout, wrong totals, or duplicated rows
- Planning migrations and DDL that must not take a live database down
- Operating a database: backups, restores, monitoring, pooling, replication, partitioning
- Moving data in or out: CSV loads, dumps, engine-to-engine migrations
- Not for PostgreSQL server internals (vacuum tuning,
work_mem, xid wraparound) — that ispg; not for ORM-level modeling in a framework — that isprisma
Quick Reference
| Situation | Play |
|---|---|
| Query slow, cause unknown | EXPLAIN (ANALYZE, BUFFERS), fix the worst node first (→ Reading EXPLAIN, then performance.md) |
| Query was fast yesterday | Stats, data growth, or plan flip — the regression chain in debug.md |
| Index exists but is not used | Function on the column, type mismatch, wrong column order, or low selectivity (→ Traps, performance.md) |
| Totals inflated after adding a JOIN | 1:N fan-out — aggregate before joining (→ Traps) |
| Rows missing after adding a JOIN | LEFT JOIN filtered in WHERE became an inner join (→ Traps) |
| Paginating past the first few thousand rows | Keyset, never OFFSET (patterns.md) |
| Deadlock, lock timeout, or "could not obtain lock" | transactions.md — lock ordering and isolation |
| "Too many connections" / app hangs on connect | Pool sizing before max_connections (operations.md, orm.md) |
| Read-modify-write race, job queue | SELECT ... FOR UPDATE, add SKIP LOCKED for queues (patterns.md) |
| Schema change on a live table | Expand → migrate → contract, lock_timeout first (operations.md) |
| Designing a model from scratch | Keys, cardinality, normal forms, when to denormalize (modeling.md) |
| Known shape needed (tenants, tags, audit, state, history) | schemas.md |
| Storing or querying JSON / semi-structured data | json.md |
| Cohorts, funnels, retention, rollups, materialized views | analytics.md |
| Loading a CSV, dump/restore, engine-to-engine move | data-loading.md |
| Timestamps off by hours, DST, week/fiscal boundaries | datetime.md |
| Statement works on one engine, fails on another | dialects.md |
| Grants, least privilege, RLS, PII erasure, encryption | security.md |
| Seeding fixtures, isolating tests, testing a migration | testing.md |
| ORM emits terrible SQL, N+1, mystery transactions | orm.md |
| Single node at its limit: replicas, sharding, caching | scaling.md |
| Choosing an engine | SQLite embedded/local · PostgreSQL default for servers · MySQL when the platform dictates it · SQL Server in .NET/Windows shops (dialects.md) |
| Anything else | Reproduce on the smallest table that shows it, then: schema-shaped → modeling.md/schemas.md · query-shaped → patterns.md · slow → performance.md · ops-shaped → operations.md |
Core Rules
- Parameterize values; allowlist identifiers. Placeholders (
?,$1) stop injection for values, but table/column names cannot be bound — when those are dynamic, check them against a hardcoded allowlist, never interpolate user input. Full attack surface, includingLIKEandORDER BYinjection:security.md. - BIGINT (or UUIDv7) primary keys by default.
INToverflows at 2,147,483,647 — at a sustained 100 inserts/s that is 2.1B ÷ 100/s ≈ 248 days, and the fix is an outage-grade type change. Random UUIDv4 keys fragment the B-tree; UUIDv7/ULID keep insert locality (modeling.md). - Index for the query shape: equality columns first, then range/sort.
(user_id, created_at)servesWHERE user_id = ? AND created_at > ?andWHERE user_id = ?alone — nevercreated_atalone. A sequential scan on a filter matching more than roughly 5-10% of rows is the planner being right, not broken. - Index every foreign key column yourself. MySQL/InnoDB creates the index automatically; PostgreSQL, SQLite, and SQL Server do not. Without it, every join on the FK and every parent
DELETE(worse withON DELETE CASCADE) scans the whole child table — the slowest delete in most schemas is this one missing index. - Transactions stay short and never wait on the outside world. No HTTP calls, no user input inside
BEGIN...COMMIT: open transactions hold locks, and in PostgreSQL they also block vacuum, causing table bloat. Anything open past the >1 min monitoring threshold (operations.md) gets investigated. - NULL is three-valued.
NOT IN (subquery)returns zero rows if the subquery yields a single NULL — useNOT EXISTS.x = NULL
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- _meta.json
- analytics.md
- data-loading.md
- datetime.md
- debug.md
- dialects.md
- json.md
- memory-template.md
- modeling.md
- operations.md
- orm.md
- patterns.md
- performance.md
- scaling.md
- schemas.md
- security.md
- setup.md
- testing.md
- transactions.md
FAQ
Что делает скилл SQL?
Writes, reviews, and optimizes SQL queries; designs schemas, indexes, and constraints; plans migrations for any relational database. Use when a query is slow, EXPLAIN shows a sequential scan, or an index is ignored; when rows come back duplicated, missing, or with inflated totals after a JOIN; on deadlocks, lock timeouts, "too many connections", or transactions that never commit; when designing tables, keys, and column types, normalizing or denormalizing a model, or deciding between a JSON column and real columns; for ALTER TABLE on a live table, expand-migrate-contract rollouts, backups and restores, replication lag, connection pooling, partitioning, bulk CSV imports, and moving data between engines; for window functions, CTEs, keyset pagination, upserts, full-text search, multi-tenancy, row-level security, and timezone handling in MySQL, SQLite, MariaDB, or SQL Server. Not for PostgreSQL server internals such as vacuum tuning and work_mem sizing, and not for ORM schema modeling inside a framework.
Как установить скилл SQL?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл SQL запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…