Prompt Engineering Database Schema Design

Schema Design & ERD Prompt — Entities, Relationships, and Keys

Turn product requirements and key entities into an ERD-ready schema spec: tables, fields, primary and foreign keys, relationships with cardinality, indexes, and constraints — with the modeling gaps named as open questions.

Overview

Schema design fails when structure runs ahead of requirements — tables nobody needed, many-to-many relationships discovered in production, foreign keys with no decided delete behavior. This prompt works the other way: it takes the product requirements, the known entities and workflows, and the constraints, and produces an ERD-ready textual specification — a domain model, an entity/table list, fields and types, relationships with explicit cardinality, primary and foreign keys with their on-delete behavior, access-pattern-driven indexes, constraints, data-lifecycle and privacy notes, and a diagram-ready relationship summary. It normalizes to 3NF by default and justifies any denormalization, traces every table and key back to a requirement, and refuses to guess where the requirements are silent — the unresolved modeling questions are named as open questions, not quietly decided. It is a design spec to review and turn into migrations, not a set of raw migrations and not a visual diagram.

How to use this resource

  1. Anchor to the requirements

    Entities, keys, and relationships trace to stated requirements — the gaps become open questions, not guesses.

  2. Model relationships explicitly

    Every association gets a direction and a cardinality, and every many-to-many resolves to an explicit join table.

  3. Make it ERD-ready

    A diagram-ready relationship summary plus migration cautions, so the spec turns into tables and an ERD without rework.

Why This Works

  • Requirement tracing keeps the schema honest — no speculative tables that complicate every future migration
  • Explicit cardinality and join-table resolution prevent the many-to-many that gets discovered in production
  • Naming open questions instead of guessing surfaces the modeling decisions that are expensive to reverse, while they are still cheap

Best for

  • Designing a new database schema from product requirements
  • Turning entities and workflows into tables, keys, and relationships
  • Preparing an ERD-ready data model before writing migrations
  • Reviewing whether a data model has the right tables, keys, and relationships

Not for

  • Optimizing an existing slow SQL query — that's the SQL Optimization Prompt
  • Finding which indexes a workload is missing — that's Missing Index Analysis
  • Generating production migrations directly — design the schema here first, then write migrations
  • Drawing a visual ERD — this produces an ERD-ready textual model, not a diagram

Use cases

  • Designing the data model for a new SaaS product from its requirements
  • Turning a CRM's contacts, accounts, deals, and pipeline into a relational schema
  • Preparing an ERD-ready spec a team can review before any migration is written

FAQ

Will this schema prompt output an actual ERD diagram or migration files?

Neither — it produces an ERD-ready textual specification. The instruction is "Do not draw a visual diagram; describe the relationships precisely enough that someone else could," and section 10 gives a diagram-ready relationship summary like "User 1—N Order." The notFor line sends production migrations elsewhere. It's a markdown design spec to review, then hand to whoever writes the migrations or draws the diagram.

How does this prompt handle a many-to-many relationship between entities?

It refuses to leave one implicit — section 4 requires "Resolve every many-to-many into an explicit join table," written as A —(N:M)— B with direction and meaning, e.g. "Order N—M Product via OrderItem." It normalizes to 3NF by default and justifies any denormalization. The prompt generates the spec; your team reviews the modeling before migrating.

What does this prompt do when my product requirements don't decide something?

It names the gap instead of guessing. The rule is "Where the requirements don't decide a modeling question, put it in Open Questions — don't quietly pick one," and section 11 collects every assumption and unresolved gap with the question that would settle each. So a foreign key with no decided on-delete behavior surfaces as an open question. You resolve those before turning the spec into migrations.

More resources from Markdown Output Builder

Resources that pair well

Related tools

Projects that use this resource

Tip: Save time by exploring related resources and tools that integrate with this resource.