database

database is a skill for Claude Code from xiaobei930/cc-best. It costs 25 tokens per session (1,660 once invoked), scanned A, original, MIT.

A reusable guide for designing databases, writing queries, improving query speed, managing schema changes, and adding indexes. It includes general conventions and database-specific guidance for systems such as PostgreSQL, MySQL, Oracle, and SQLite.

In plain words
What is it for?
Use it when creating database schemas, choosing relationships, writing queries, planning migrations, or deciding which columns to index.
Why use it?
It helps avoid inconsistent table designs, weak relationships, and queries that become slow as data grows.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the cc-best plugin — 19 skills, 44 commands, 8 agents, 20 hooks shipped together

Good fit Use it when creating database schemas, choosing relationships, writing queries, planning migrations, or deciding which columns to index.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/xiaobei930/cc-best/database
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add xiaobei930/cc-best --skill database
Clone the repo
git clone --depth 1 https://github.com/xiaobei930/cc-best

Made for: Claude Code.

Or install cc-best, the plugin that ships this one along with the rest of its 19 skills, 44 commands, 8 agents, 20 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for database

README.md
[![agentmods](https://agentmods.dev/badge/skills/xiaobei930/cc-best/database/github.svg)](https://agentmods.dev/skills/xiaobei930/cc-best/database)
Your own site
<a href="https://agentmods.dev/skills/xiaobei930/cc-best/database"><img src="https://agentmods.dev/badge/skills/xiaobei930/cc-best/database/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for database

Your own site · 80×15
<a href="https://agentmods.dev/skills/xiaobei930/cc-best/database"><img src="https://agentmods.dev/badge/skills/xiaobei930/cc-best/database.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 25 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,660 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00025 $0.01660
Opus 5.5 $0.00010 $0.00664
Sonnet 5.5 $0.00005 $0.00332
Haiku 4.5 $0.00003 $0.00166

Measured 1mo ago against content hash a871a6e7be53, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

database scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/database/SKILL.md · 215 lines

How it starts

The opening of the file, as written. The whole thing — 215 lines — stays where its author put it; the contents beside it link to each section on GitHub.

数据库模式技能

关联 Agent: architect — 架构设计时加载数据库约束上下文

本技能提供数据库设计和操作的最佳实践,支持多数据库按需加载。

触发条件

  • 设计数据库 Schema
  • 编写数据库查询
  • 优化查询性能
  • 管理数据库迁移
  • 配置索引

数据库专属模式

根据项目技术栈,加载对应的数据库专属文件:

数据库 加载文件 适用场景
PostgreSQL postgres.md 企业应用、复杂查询
MySQL mysql.md Web 应用、读多写少
Oracle oracle.md 大型企业、高并发 OLTP
SQLite sqlite.md 嵌入式、移动端、本地化

检测方式: 根据连接字符串、ORM 配置或项目依赖确定数据库类型。


通用 Schema 设计

命名规范

-- 表名:小写下划线,复数形式
users, order_items, user_preferences

-- 列名:小写下划线
created_at, updated_at, user_id, is_active

-- 索引名:idx_表名_列名
idx_users_email, idx_orders_user_id_created_at

-- 外键名:fk_表名_关联表
fk_orders_users

必备字段

CREATE TABLE users (
    id BIGINT PRIMARY KEY,           -- 主键
    -- 业务字段...
    created_at TIMESTAMP NOT NULL,   -- 创建时间
    updated_at TIMESTAMP NOT NULL,   -- 更新时间
    deleted_at TIMESTAMP             -- 软删除
);

关系设计

关系类型 设计方式 示例
一对多 子表添加外键 orders.user_id → users
多对多 中间表 + 联合主键 user_roles(user_id, role_id)
一对一 子表主键 = 外键 user_settings.user_id

通用索引策略

何时创建索引

  • ✅ WHERE 条件频繁使用的列
  • ✅ JOIN 关联的列
  • ✅ ORDER BY / GROUP BY 的列
  • ❌ 很少查询的列
  • ❌ 值重复率高的列(如性别)
  • ❌ 频繁更新的列

索引类型选择

查询模式 推荐索引
WHERE col = value B-tree
WHERE col > value B-tree
全文搜索 全文索引
JSON 字段查询 GIN/JSON 索引
时序数据范围查询 BRIN(PG)

复合索引原则

-- 规则:等值列在前,范围列在后
-- 查询:WHERE status = 'active' AND created_at > '2024-01-01'

-- ✅ 正确顺序
CREATE INDEX idx_orders_status_created ON orders(status, created_at);

-- ❌ 错误顺序(范围列在前会导致后续列无法使用索引)
CREATE INDEX idx_orders_created_status ON orders(created_at, status);

N+1 问题

问题示例

获取 100 个用户及其订单:
1 次查询获取用户 + 100 次查询获取每个用户的订单 = 101 次查询

Read the full file on GitHub · 215 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 215 lines · 25 tokens per session scan A a871a6e7be53

Subscribe to this mod's changes

database is a skill published in the GitHub repository xiaobei930/cc-best (48 stars, last pushed 4mo ago), licensed MIT. It adds 25 tokens to every session and 1,660 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

optimize

Analyze and suggest performance improvements for code, queries, or systems.

FlorianBruniaux/claude-code-ultimate-guide · 15 tokens

eval-hooks

Audit Claude Code and Codex hooks for validity, safety, and correctness across settings.json, hooks.json, config.toml, plugin, and skill or agent frontmatter hooks. Resolves each command, checks event names, handler types, matchers, exit-code and JSON decision strategy, and timeouts against each host's documented…

FlorianBruniaux/claude-code-ultimate-guide · 115 tokens

audit-agents-skills

Audit Claude Code agents, skills, and commands for quality and production readiness. Use when evaluating skill quality, checking production readiness scores, or comparing agents against best-practice templates.

FlorianBruniaux/claude-code-ultimate-guide · 41 tokens

design-patterns

Detect, suggest, and evaluate GoF design patterns in TypeScript/JavaScript codebases. Use when refactoring code, applying singleton/factory/observer/strategy patterns, reviewing pattern quality, or finding stack-native alternatives for React, Angular, NestJS, and Vue.

FlorianBruniaux/claude-code-ultimate-guide · 59 tokens

eval-agents

Audit custom subagent definitions for Claude Code (.claude/agents/.md) and Codex (.codex/agents/.toml): loadability against the native schema, description overlap, model tier, tool scope, and headless-safe instructions. Use when onboarding to a project with agents, after adding or importing agents, or when the parent…

FlorianBruniaux/claude-code-ultimate-guide · 80 tokens

eval-skills

Audit a project or library of skills for metadata, trigger boundaries, workflow completion criteria, local resource closure, instruction economy, tool scope, effort, and routing evidence. Use before shipping skills, after importing a skill collection, or when a skill triggers too often or not at all.

FlorianBruniaux/claude-code-ultimate-guide · 60 tokens