Design a normalized database schema

Turn business requirements into a normalized relational schema with entities, keys, constraints, indexes, DDL and validation queries. Designed for ChatGPT, Claude and Gemini. It includes 6 customizable variables and you can copy it for free in one click.

Advanced · Code · Pending editorial review

Designed for:

Prompt

Act as a data architect experienced in relational modeling and {{engine}}.

Application context: {{application}}.
Functional requirements (what the system must store and allow): {{requirements}}.
Estimated volume: {{volume}}.
Most frequent queries: {{queries}}.

Deliver, in this order:
1. The entities and attributes derived from the requirements, flagging any ambiguity you need me to clarify.
2. An entity-relationship diagram in Mermaid syntax (`erDiagram`) with cardinalities.
3. The rationale for normalizing to 3NF (and where deliberate denormalization makes sense, with the reason).
4. Complete DDL for {{engine}}: appropriate data types, primary keys (and the choice between integers, UUIDs or ULIDs), foreign keys with a reasoned `ON DELETE`, `NOT NULL`, `UNIQUE`, `CHECK` constraints and defaults.
5. Recommended indexes for the frequent queries, explaining each one.
6. A strategy for soft deletes, auditing (`created_at`, `updated_at`) and sensitive personal data.
7. Three sample SQL queries proving the schema covers the main use cases.
8. Schema evolution risks and how to handle them with migrations.

Constraints:
- Do not add entities that do not follow from the requirements without telling me.
- Use {{naming_language}} table and column names in snake_case.
- If critical information is missing, ask me before writing the DDL.

How to use it

  1. Write requirements as simple sentences: “a customer can have several addresses”.
  2. Add the queries you will run most often; they drive the indexes.
  3. Paste the Mermaid diagram into a compatible viewer to review it.
  4. Run the DDL on a test database before writing the final migrations.

Usage example

Application: language school management · Requirements: students, courses, class groups, enrollments and monthly payments · Engine: PostgreSQL 16.

Sample output

4. DDL (excerpt, PostgreSQL 16)

CREATE TABLE students (
  id          bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  full_name   text NOT NULL,
  email       text NOT NULL UNIQUE,
  created_at  timestamptz NOT NULL DEFAULT now(),
  deleted_at  timestamptz                -- soft delete
);

CREATE TABLE enrollments (
  id              bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  student_id      bigint NOT NULL REFERENCES students (id) ON DELETE RESTRICT,
  class_group_id  bigint NOT NULL REFERENCES class_groups (id) ON DELETE RESTRICT,
  enrolled_on     date NOT NULL DEFAULT current_date,
  UNIQUE (student_id, class_group_id)
);

CREATE TABLE monthly_payments (
  id             bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  enrollment_id  bigint NOT NULL REFERENCES enrollments (id) ON DELETE RESTRICT,
  period         date NOT NULL CHECK (extract(day FROM period) = 1),
  amount_cents   integer NOT NULL CHECK (amount_cents >= 0),
  paid_at        timestamptz,
  UNIQUE (enrollment_id, period)
);

-- Partial index for "students with overdue payments"
CREATE INDEX idx_payments_unpaid ON monthly_payments (period) WHERE paid_at IS NULL;

ON DELETE RESTRICT prevents losing payment history if someone deletes a student, which is why soft deletes are used. Amounts are stored in cents to avoid rounding errors.

Ambiguities

  • Does one payment cover a single enrollment or all of a student's enrollments that month? [FILL IN]…

Key facts

Category
Programming & development · SQL
Output type
Code
Level
Advanced
Designed for
ChatGPT, Claude and Gemini
Verified in
Pending editorial verification
Variables
Database engine, Application, Requirements, Estimated volume, Frequent queries and Naming language
Language
English
Price
Free, no sign-up
Updated
Nov 7, 2026

Frequently asked questions

Should I always normalize to 3NF?

It is a sound starting point that prevents duplicates and inconsistencies. For reporting or extremely read-heavy tables, denormalizing can pay off, but it should be a conscious, documented decision.

UUIDs or integer IDs?

Integers are compact and fast; UUIDs or ULIDs avoid exposing record counts and can be generated outside the database. The prompt asks the AI to justify the choice.

What is this prompt for?

Turn business requirements into a normalized relational schema with entities, keys, constraints, indexes, DDL and validation queries.

Which AI tools does it work with?

It is designed for ChatGPT, Claude and Gemini. We have not verified it in these tools yet, so results may vary between them.

How do I customize the prompt?

Click “Customize” and fill in the variables (Database engine, Application, Requirements, Estimated volume, Frequent queries and Naming language). The text updates instantly and you can then copy it in one click. Values are stored only in your browser.

Do I need experience to use it?

It is advanced: it is meant for people with experience in the topic who can evaluate and adjust the result.

Is this prompt free?

Yes. Every HomeCasa Prompts prompt is free, with no sign-up or subscription. You can also use them in professional projects.

Can I trust the AI output?

Treat it as a high-quality draft: always check data, figures and important claims before publishing or making decisions.

Related prompts