# Generate → Refine → Derive — Checkliste & Starter-Regeln / Checklist & Starter Rules

Begleit-Download zum Artikel **„SQL-Konventionen mit Claude Code ableiten"**.
Companion download to **"Deriving SQL Conventions with Claude Code"**.

→ https://sql.marcus-belz.de/sql-konventionen-mit-claude-code-ableiten/

So baust du dir aus manuellen Korrekturen ein KI-durchgesetztes Regelwerk.
Turn manual corrections into an AI-enforced rule set.

---

## Der Loop / The loop

1. **Generate** — KI erzeugt das SQL-Artefakt. / AI generates the SQL artifact.
2. **Refine** — von Hand in den Zielzustand korrigieren. / hand-correct it into the target state.
3. **Derive** — Claude die Differenz analysieren und die Regel ableiten lassen. / have Claude analyze the diff and derive the rule.
4. **Codify** — Regel in `.claude/rules/<typ>.md` ablegen. / drop the rule into `.claude/rules/<type>.md`.
5. **Enforce** — Agent lädt sie und generiert regelkonform. / the agent loads it and generates compliant code.
6. **Wiederholen / Repeat** — jeder Sonderfall schärft das Regelwerk. / each edge case sharpens the rule set.

---

## Der Derive-Prompt / The derive prompt (copy-paste)

> Compare the artifact you generated with my revised version. List the
> differences and turn them into reusable rules — each rule with a short
> rationale. Flag anything where the rationale isn't visible in the diff.

---

## Starter: `.claude/rules/procedures.md`

Format pro Regel / per rule: **Rule → Rationale → Do/Don't**.

```text
## Parameter order (identifier first)

Rule:      The identifier parameter (p_id) comes first in the signature,
           before the attribute parameters.
Rationale: WHERE id = p_id identifies the row first; applies even to INSERT,
           where id is INOUT — "identifier first" beats "inputs before outputs".
Do:        sp_upd_project(IN p_id bigint, IN p_name varchar)
Don't:     update_project(p_name, p_id)

## Naming

Rule:      snake_case, singular table names; type prefix on routines
           (sp_ / fn_ / tf_ / tr_ / vw_); parameters p_, local variables l_.
Rationale: the prefix answers "what is this?" before you read the name.
Do:        sp_upd_project, fn_is_null_or_empty
Don't:     update_project, isNullOrEmpty
```

---

## Gezielter manueller Input / Targeted manual input

Manche Regeln stehen nicht im Diff — gib sie explizit vor:
Some rules aren't in the diff — state them explicitly:

- Reihenfolgen mit Logik / orderings that follow a logic (identifier-first, checks-before-mutations)
- bewusste Abweichungen von Faustregeln / deliberate departures from rules of thumb
- Namensgebung mit fachlichem Hintergrund / naming with a domain background

Und: Nicht jede Korrektur verdient eine Regel — codifiziere nur, was *wiederkehrt*.
And: not every correction deserves a rule — codify only what *recurs*.
