Skip to main content

Claude Prompt for Normalization & Denormalization Decisions

Analyze your database design for when to normalize vs denormalize, with trade-off tables, migration paths, and performance comparisons.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a database architect. Analyze my current data model and advise on normalization and denormalization decisions.

**Current Schema:**
```sql
Paste your CREATE TABLE statements here
```

**Application Context:**
- Type: E-commerce platform with product catalog, orders, and analytics
- Access patterns: Product pages (high read), order creation (write-heavy), admin dashboard with aggregated stats, search with filters
- Scale: 500K products, 2M orders, 50K daily active users, growing 30% quarterly
- Consistency requirements: Order and payment data must be strongly consistent. Product catalog can tolerate 5-minute staleness.

**Analyze and Recommend:**

1. **Normalization Audit (Current State):**
   Evaluate the current schema against normal forms:
   - **1NF:** Are there any repeating groups or arrays stored in single columns?
   - **2NF:** Are all non-key attributes fully dependent on the entire primary key?
   - **3NF:** Are there any transitive dependencies?
   - **BCNF:** Are there any non-trivial functional dependencies where the determinant is not a superkey?

   For each violation found:
   - What it is and why it's problematic
   - The specific data anomaly it can cause (insert, update, or delete anomaly)
   - How to fix it (with ALTER TABLE / CREATE TABLE statements)

2. **Strategic Denormalization Recommendations:**
   For each potential denormalization:

   | Denormalization | Why | Trade-off | When to Use | When NOT to Use |
   |----------------|-----|-----------|-------------|-----------------|

   Common patterns to evaluate:
   - **Computed columns:** Store calculated values instead of computing on read
   - **Redundant columns:** Copy frequently joined columns to avoid JOINs
   - **Summary tables:** Pre-aggregated data for reporting/dashboards
   - **JSON columns:** Semi-structured data that's always read together
   - **Materialized views:** Cached query results refreshed on schedule
   - Polymorphic relationships (comments, tags, addresses) — should they use separate tables per type or a shared table?

3. **Decision Framework:**
   For each table/relationship, apply this decision tree:
   ```
   Is the data read 10x more than written? → Consider denormalization
   Is consistency critical (financial, medical)? → Stay normalized
   Are JOINs causing measurable latency? → Measure first, then denormalize
   Is the team small with no DBA? → Prefer simplicity over optimization
   ```

4. **Migration Path:**
   For each recommended change:
   - Step 1: Add new structure (backward compatible)
   - Step 2: Backfill data with a migration script
   - Step 3: Update application code to use new structure
   - Step 4: Verify data consistency
   - Step 5: Remove old structure (after validation period)

   Include the actual SQL migration scripts.

5. **Performance Comparison:**
   For the top 3 most impactful changes:
   - Query BEFORE (with EXPLAIN output analysis)
   - Query AFTER (with expected EXPLAIN improvement)
   - Estimated latency improvement
   - Storage trade-off

6. **Monitoring Queries:**
   SQL queries to monitor the health of the denormalized data:
   - Data consistency checks (does the denormalized value match the source?)
   - Staleness detection (how old is the cached/computed data?)
   - Storage growth tracking

What this prompt does

This prompt turns the model into a database architect that audits your schema and advises on where to normalize and where to strategically denormalize. You provide your [current_schema] plus application context — [app_type], [access_patterns], [scale_info], and [consistency_needs] — and it evaluates the design against normal forms, flags anomalies, and recommends targeted denormalizations with migration paths.

The structure keeps it honest. It checks 1NF through BCNF and, for each violation, names the specific insert, update, or delete anomaly it can cause. Then it evaluates denormalization patterns (computed columns, redundant columns, summary tables, JSON columns, materialized views) in a trade-off table, gated by a decision tree that weighs your read/write ratio and [consistency_needs]. Because you supply [access_patterns] and [scale_info], it can tell you when a JOIN is worth removing and when consistency should win. The [additional_pattern] slot lets you pose a specific question, like whether polymorphic relationships belong in shared or per-type tables.

When to use it

  • When a data model has grown messy and you need to decide where denormalization actually pays off.
  • To audit a schema against normal forms and find anomalies before they corrupt data.
  • When JOINs are causing measurable latency and you're weighing a redundant column or summary table.
  • Before scaling a read-heavy product where pre-aggregation or materialized views might help.
  • To get concrete, reversible migration steps instead of a risky one-shot schema change.

Example output

You get a normalization audit (1NF/2NF/3NF/BCNF) with each violation, the anomaly it causes, and the ALTER/CREATE statements to fix it. Then a denormalization table with columns for the change, why, the trade-off, and when-to-use vs. when-not-to. It includes a decision framework, a five-step backward-compatible migration path with actual SQL, a before/after performance comparison on the top changes, and monitoring queries to detect staleness and consistency drift in denormalized data.

Pro tips

  • Paste the full [current_schema] including constraints and keys so the BCNF check can spot non-trivial functional dependencies.
  • Be specific in [consistency_needs]: mark which tables must be strongly consistent (payments, orders) and which can tolerate staleness, so it never denormalizes the wrong data.
  • Describe [access_patterns] by read vs. write intensity per area — the decision tree leans on the 10x-read heuristic to recommend denormalization.
  • Measure JOIN latency yourself before acting. I make the model insist on benchmarks because denormalization is a bet, not a default.
  • Use [additional_pattern] to ask about a real modeling dilemma you're stuck on, like polymorphic comments or tags.
  • Run the generated migration in stages (add, backfill, switch, verify, drop) and keep the validation period before removing old structures.

Frequently Asked Questions

Does this prompt check all normal forms?
Yes, it evaluates the schema against 1NF, 2NF, 3NF, and BCNF. For each violation it explains the specific insert, update, or delete anomaly it can cause and gives ALTER or CREATE TABLE statements to fix it.
How does it decide when to denormalize?
It applies a decision tree weighing your read-to-write ratio, whether consistency is critical, whether JOINs cause measurable latency, and team size. You supply `[consistency_needs]` and `[access_patterns]` so it can apply the tree to your situation.
Will it give me actual migration SQL?
Yes. For each recommended change it outlines a five-step, backward-compatible migration (add, backfill, update code, verify, remove) and includes the SQL migration scripts rather than just describing the steps abstractly.
Can it handle polymorphic relationships?
Yes, if you raise it. The `[additional_pattern]` variable defaults to asking whether polymorphic comments, tags, and addresses should use per-type tables or a shared table, and you can swap in your own modeling question.
Does it protect financial data from over-denormalization?
It does when you tell it. Mark order and payment tables as strongly consistent in `[consistency_needs]`, and the decision tree keeps that data normalized instead of trading consistency for read speed.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Data & SQL Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support