Command Palette

Search for a command to run...

Back to skills
skill № 66475

SQL

Writes, reviews, and optimizes SQL queries; designs schemas, indexes, and constraints; plans migrations for any relational database. Use when a query is slow…

FreeNo executable scripts
clawicby clawic★ 23 GitHub stars

Install SQL in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

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 is pg; not for ORM-level modeling in a framework — that is prisma

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

  1. 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, including LIKE and ORDER BY injection: security.md.
  2. BIGINT (or UUIDv7) primary keys by default. INT overflows 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).
  3. Index for the query shape: equality columns first, then range/sort. (user_id, created_at) serves WHERE user_id = ? AND created_at > ? and WHERE user_id = ? alone — never created_at alone. A sequential scan on a filter matching more than roughly 5-10% of rows is the planner being right, not broken.
  4. 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 with ON DELETE CASCADE) scans the whole child table — the slowest delete in most schemas is this one missing index.
  5. 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.
  6. NULL is three-valued. NOT IN (subquery) returns zero rows if the subquery yields a single NULL — use NOT EXISTS. x = NULL
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

  • _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

What does the SQL skill do?

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.

How do I install the SQL skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the SQL skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare SQL with