Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Sql Database

ASecurity

Design and work with databases — schema design, indexes for real query shapes, query optimization with EXPLAIN, N+1 elimination, reversible migrations, transactions and locking. Use for SQL queries, schema questions, slow queries, and database migrations.

2 stars
0 votes
0 copies
0 views
Added 10/3/2026
ai-agentsgosqldatabasesecurityperformance

Security Analysis

A100/100

Scanned 10/3/2026

$npx -y skills add ivanvp91/TRCode --skill sql-database --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Database?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Sql Database
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ivanvp91-sql-database/badge)](https://www.skillsdirectory.com/skills/ivanvp91-sql-database)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: sql-database
description: Design and work with databases — schema design, indexes for real query shapes, query optimization with EXPLAIN, N+1 elimination, reversible migrations, transactions and locking. Use for SQL queries, schema questions, slow queries, and database migrations.
description_ru: Проектирование и работа с базами данных — схема, индексы под реальные запросы, оптимизация запросов через EXPLAIN, устранение N+1, обратимые миграции, транзакции и блокировки. Для SQL-запросов, вопросов схемы, медленных запросов и миграций БД.
triggers: база данных, базу данных, database, sql, запрос sql, sql запрос, postgres, postgresql, mysql, sqlite, mongodb, схема данных, схема бд, миграция бд, миграции, индексы, index, orm, join, джойн, таблицы бд, explain, транзакция, transaction, deadlock, нормализация
---

# SQL and databases

## 1. Schema from the queries, not the nouns
List the top queries the app will actually run (reads AND writes, with rough frequency) before drawing tables — the schema serves them. Then:
- Normalize until it hurts, denormalize where a measured read path demands it — and mark every denormalization with how it stays in sync.
- Right types: numeric money as `DECIMAL` never float; timestamps with timezone discipline (store UTC); enums/checks for closed sets; no `VARCHAR(255)` cargo cult — size by the domain.
- Every table: a primary key, `created_at`, and foreign keys with explicit `ON DELETE` behavior chosen on purpose (cascade vs restrict vs set null — say why).
- Names: consistent convention matching the existing schema; singular/plural — copy what the project already does.

## 2. Indexes are for query shapes
- Index what appears in `WHERE`, `JOIN ... ON`, and `ORDER BY` of real queries; composite indexes ordered by selectivity and prefix use (an index on `(a,b)` serves `WHERE a` but not `WHERE b`).
- Foreign key columns get indexes — most engines don't do it automatically.
- Every index costs writes and space: don't index low-cardinality flags alone, don't duplicate prefixes, drop what `EXPLAIN` never uses.
- Uniqueness constraints live in the database (`UNIQUE`), not only in app code — races will find the gap.

## 3. Query work: EXPLAIN or it didn't happen
- Diagnose slow queries with `EXPLAIN` (ANALYZE where safe): look for full scans on big tables, missing index usage, row estimates wildly off (stale stats), sorts spilling.
- The N+1 pattern — a query per loop iteration — becomes one query with `JOIN`/`IN`/eager loading; it hides inside ORMs, so check the generated SQL, not the ORM code.
- Fetch what's needed: no `SELECT *` in hot paths, `LIMIT` on anything unbounded, pagination by keyset (`WHERE id > last`) not `OFFSET` for deep pages.
- Parameterized queries always — string-built SQL is an injection, security aside from performance.

## 4. Migrations: forward safely, backward possibly
- Every schema change is a migration file, ordered, in version control — no live hand-edits to production schemas.
- State reversibility per migration: the `down` path, or explicitly "irreversible, data-destroying" so the user decides.
- Danger moves on big/live tables — adding NOT NULL without default, type changes, index builds locking writes — get the safe recipe: add nullable → backfill in batches → add constraint; create index concurrently where the engine supports it.
- Deploy order when app and schema change together: expand (add new alongside old) → migrate code → contract (drop old) — never rename in one hop under a running app.

## 5. Transactions and concurrency
- A transaction wraps what must be atomic — and nothing more; long transactions holding locks across network calls are deadlock bait.
- Read-modify-write races (balances, counters, inventory): solve with atomic updates (`UPDATE ... SET x = x + 1`), row locks (`SELECT ... FOR UPDATE`), or optimistic versioning — pick one and name it.
- Retry on deadlock/serialization failures is normal; make the transaction idempotent so the retry is safe.

## What not to do
- No schema invented before seeing the queries; no float money; no app-level uniqueness "checks" instead of constraints.
- No `OFFSET 100000` pagination, no unparameterized SQL, no `SELECT *` in loops.
- No irreversible migration run without the user acknowledging what's destroyed; back up before destructive changes.
- Don't reach for a new database technology when an index would do.

## Answer format
For schema: the DDL with a line of rationale per non-obvious choice. For slow queries: EXPLAIN before → the change → EXPLAIN/timing after. For migrations: the migration file, its reversibility, and the deploy order if the app changes too.

Attribution

ivanvp91ivanvp91
View sourceSee grades on GitHubMore from ivanvp91 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698431 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →