Use it when you are

  • Designing the first schema for a new application or service
  • Adding a new area, such as billing or permissions, to an existing database
  • Checking a schema you drafted yourself against an independent design
  • Turning a spreadsheet or document-shaped data model into normalized tables

Why this prompt works

You confirm relationships before they become foreign keys

A wrong cardinality is cheap to fix in a sentence and expensive to fix in a populated table. Step 1 puts each relationship, with optionality and delete behavior, into wording a non-specialist can verify. Reading that list is usually the fastest review you can give a schema.

Business rules are asked for as inputs and returned as constraints

The prompt requests rules, then requires NOT NULL, UNIQUE and CHECK constraints that enforce them. That closes the usual gap in generated schemas, where tables have the right columns but nothing prevents a duplicate invoice number or a negative quantity.

No index without a query

Indexes cost write performance and storage, and models tend to add them to every foreign key and timestamp by reflex. Tying each one to a query from your list keeps the set small and gives you the reasoning to revisit when the workload changes.

The schema is tested against its own workload

Writing the top three queries in step 5 is a self-check. If a common read needs five joins or a subquery per row, the model is told to revise the design and report the change, which catches modeling mistakes that look fine as a table list.

How to use it

  1. Write business rules as prohibitions and guarantees: what must be unique, what cannot change, what cannot exist without something else.
  2. List the real queries your application will run most often, including the filters and sort order.
  3. Select your engine. Types and constraint features differ, and the prompt restricts the model to that engine.
  4. Read step 1 of the reply first and correct any sentence that is not true of your business.
  5. Run the DDL against an empty local database to confirm it executes, then try the step 5 queries with a little sample data.
  6. Resolve the open questions before writing a migration, since they often hide a missing rule.

AI model compatibility

ModelStatusNotes
ChatGPTExpected to workIf you want a diagram, ask for it in a follow-up message once the DDL is settled; requesting it up front tends to shorten the sections that matter more.
ClaudeExpected to workWhen pasting existing DDL, put it inside XML-style tags such as <existing_schema>, in line with Anthropic's guidance on separating reference material from instructions.
GeminiExpected to workNo model-specific adjustment needed. Paste the prompt as written.
CursorExpected to workIn a repo, point the conventions field at your existing migration files or ORM schema so new tables follow the same naming and key types, and ask for the result as a new migration file.

“Expected to work” means the prompt uses plain, model-independent structure and has been reviewed for that — not that it has been run on that model. A model is marked Tested only when a test record is published below.

Worked example

Scenario: An illustrative case: a small team building an invoicing tool for freelancers.

Example: filled-in prompt
# Role
You are a database engineer designing a relational schema that will run in production for years. You prefer constraints in the database over rules that live only in application code.

# Inputs
- Application: Multi-tenant invoicing tool for freelancers
- Entities and business rules: Accounts have users, clients and invoices. An invoice belongs to one client and has one or more line items. Invoice numbers are unique within an account. Status is draft, sent, paid or void. A sent invoice's line items cannot change. Payments can be partial. A client with invoices cannot be deleted.
- Database engine: PostgreSQL
- Most important queries and writes: List an account's unpaid invoices ordered by due date. Look up an invoice by account and number. Total billed and total paid per client per month. List a client's invoices newest first. Find invoices overdue as of today.
- Expected size and growth: Thousands of accounts, up to a few million invoices over three years
- Conventions, ORM or existing tables: snake_case, plural table names, UUID primary keys, created_at and updated_at on every table

# Steps

## 1. Relationships in plain language
Before any SQL, write one sentence per relationship in the form "A customer has zero or more orders; an order belongs to exactly one customer." I will check these against reality, so include optionality and whether deleting the parent should be blocked, cascaded or should null the reference.

## 2. Schema
Write CREATE TABLE statements for the engine above, runnable in order. For every table include:
- a primary key, with a one-line reason for the key type;
- foreign keys with explicit ON DELETE behavior;
- NOT NULL, UNIQUE and CHECK constraints that enforce the business rules I gave you;
- the most specific sensible type for each column. Money is never a floating-point type. Timestamps state whether they carry a time zone.

## 3. Indexes
List each index beyond those created by keys. Beside each, name the query from my list that it serves. No index without a named query.

## 4. Design decisions
In a short table: decision, alternative considered, why you chose this. Cover at least normalization versus any deliberate denormalization, how history or soft deletion is handled if the rules imply it, and anything that will be hard to change once data exists.

## 5. Query check
Write the SQL for the three most important queries from my list against your schema. If one is awkward, revise the schema and say what changed.

## 6. Open questions
Rules that were ambiguous and what you assumed.

# Constraints
- Use only features of the stated engine and say so when a feature is engine-specific.
- Do not add tables or columns for features I did not describe. Suggest them under Open questions.
- Mark every guess [ASSUMPTION]. Do not invent row counts or performance figures.

# Output format
The six numbered headings above. SQL in fenced code blocks, everything else as brief bullets or tables.

What a good response should contain

  • Relationship sentences that include "a client with invoices cannot be deleted" expressed as a restricted delete
  • A unique constraint on account and invoice number, and a CHECK or enumerated type limiting status values
  • Money stored in an exact numeric or integer minor-unit column with a currency, and a note on which was chosen
  • An index list where each entry names one of the five queries, with no unreferenced indexes
  • An open question about how the rule that sent invoices are immutable should be enforced, since a table constraint alone may not cover it

This is an illustrative scenario showing how to fill in the prompt and what to look for. It is not a recorded model output. Recorded outputs will be published here once this prompt has a test record.

Testing and editorial review

Status: Untested. Reviewed for structure and clarity by the editorial team. No recorded model test yet.

No test record has been published for this prompt yet. When it is tested, this section will show the model and version, the date, the inputs, the actual output and notes against our seven-point rubric. We do not publish numerical scores.

Editorial record
AuthorTheBestPromptFor Editorial Team — The editorial team writes, reviews and maintains the prompts and guides on TheBestPromptFor. Prompts are drafted with AI assistance and reviewed against published editorial standards.
PublishedNovember 15, 2026
Last reviewedNovember 15, 2026
Last testedNot yet tested
Version history
  • v1.0 — November 15, 2026 · Initial version

Limitations and things to check

  • The model cannot execute SQL. Run the DDL and queries before trusting them; syntax differs between engines and versions.
  • Index advice is reasoned from the queries you listed, not measured. Confirm with query plans on realistic data.
  • Some rules, such as state-dependent immutability, need triggers or application logic and may only be noted, not enforced.
  • This designs a new schema. It does not plan a zero-downtime migration of existing data.

Alternative prompts

All Web Development prompts →

Frequently asked questions

Why does the prompt want queries and not just entities?

Because the same entities can be modeled several valid ways, and the right one depends on how the data is read and written. Queries determine indexes, influence whether to denormalize and reveal missing columns. Without them, the model can only produce a textbook design.

Will it work with an ORM such as Prisma or Drizzle?

Yes. Name the ORM in the conventions field and ask, in a follow-up, for the schema in that ORM's format. Keep the SQL version as the reference, since some CHECK constraints and partial indexes may need raw SQL in a migration.

Can I use it for a NoSQL or document database?

No. The steps assume relational concepts: foreign keys, normalization and declarative constraints. Document and key-value stores are modeled around access patterns in a different way, and the output here would mislead more than it helps.

Sources and references

  1. PostgreSQL documentation: Data Definition — PostgreSQL Global Development Group
  2. Prompt engineering overview — Anthropic

Was this prompt useful?

No account needed. Do not include personal information.