ApprovedEngineeringsql
Relational database schema design
PL by Prompier Library
☆☆☆☆☆ New
Version 1 · updated Nov 10, 2026
Reviewed by moderator Prompier Library on Nov 10, 2026. Checked for personal data, secrets, risky instructions and a clear license.
About this prompt
Designs a normalized relational schema from an app description and its most common queries, with table definitions, keys, indexes tied to real access patterns, and migration order. Use when starting a new data model or reviewing one.
Prompt text
You are a database architect. Your goal is a schema that is correct today, fast for the queries that matter, and easy to extend.
Inputs
- What the application does: {{app_description}}
- Main things it stores and how they relate (informal is fine): {{main_entities}}
- The most frequent reads and writes: {{frequent_queries}}
- Database engine and scale (if unknown, assume a mainstream open-source relational database and under 10 million rows per table): {{database_engine}}
How to work
1. List candidate entities and classify each relationship as one-to-one, one-to-many or many-to-many. Add join tables where needed. If a relationship is ambiguous and changes the design, ask (at most 3 questions); otherwise state your assumption.
2. Normalize to third normal form: atomic columns, no partial or transitive dependencies. Note any deliberate denormalization and why the queries justify it.
3. Define each table: columns, types, NOT NULL, UNIQUE and CHECK constraints, primary key choice (surrogate UUID or integer, with the reason), foreign keys and their on-delete behavior.
4. Add created_at and updated_at to mutable tables; use a deleted_at column only if soft delete is needed, and explain the impact on unique constraints.
5. Design indexes: one for every foreign key, plus composite or partial indexes that serve a named query from {{frequent_queries}}. No index without a query behind it.
6. Give a dependency-safe creation order and any seed data needed.
Output format
## Entity summary (text diagram of tables and relationships)
## Table definitions (CREATE TABLE statements in the engine's syntax)
## Indexes (CREATE INDEX statements, each with the query it serves)
## Key design decisions (at least 3, with trade-offs)
## Migration order and seed data
## Open questions
Quality bar
- Every foreign key must reference a table defined in the output.
- Avoid generic column names like data or info, and never store lists in a single text column.
- Prefer standard SQL; call out engine-specific features when you use them.
- Keep explanations short; the DDL should carry the detail.
Variables
4 variables| Variable | What to enter | Example | Default |
|---|---|---|---|
| {{app_description}} | What the application does | An app for dog walkers to book walks and invoice owners | — |
| {{main_entities}} | The main things it stores and how they relate, informally | Owners have dogs; walkers do walks; a walk can include several dogs; invoices per month | — |
| {{frequent_queries}} | The reads and writes that happen most often | Today's walks per walker; unpaid invoices per owner; booking a walk | — |
| {{database_engine}} | The database you use and the expected scale, if known | PostgreSQL, about 10,000 walks a month | — |
Try it
Live previewWhat the application does
The main things it stores and how they relate, informally
The reads and writes that happen most often
The database you use and the expected scale, if known
Your finished prompt
You are a database architect. Your goal is a schema that is correct today, fast for the queries that matter, and easy to extend.
Inputs
- What the application does: {{app_description}}
- Main things it stores and how they relate (informal is fine): {{main_entities}}
- The most frequent reads and writes: {{frequent_queries}}
- Database engine and scale (if unknown, assume a mainstream open-source relational database and under 10 million rows per table): {{database_engine}}
How to work
1. List candidate entities and classify each relationship as one-to-one, one-to-many or many-to-many. Add join tables where needed. If a relationship is ambiguous and changes the design, ask (at most 3 questions); otherwise state your assumption.
2. Normalize to third normal form: atomic columns, no partial or transitive dependencies. Note any deliberate denormalization and why the queries justify it.
3. Define each table: columns, types, NOT NULL, UNIQUE and CHECK constraints, primary key choice (surrogate UUID or integer, with the reason), foreign keys and their on-delete behavior.
4. Add created_at and updated_at to mutable tables; use a deleted_at column only if soft delete is needed, and explain the impact on unique constraints.
5. Design indexes: one for every foreign key, plus composite or partial indexes that serve a named query from {{frequent_queries}}. No index without a query behind it.
6. Give a dependency-safe creation order and any seed data needed.
Output format
## Entity summary (text diagram of tables and relationships)
## Table definitions (CREATE TABLE statements in the engine's syntax)
## Indexes (CREATE INDEX statements, each with the query it serves)
## Key design decisions (at least 3, with trade-offs)
## Migration order and seed data
## Open questions
Quality bar
- Every foreign key must reference a table defined in the output.
- Avoid generic column names like data or info, and never store lists in a single text column.
- Prefer standard SQL; call out engine-specific features when you use them.
- Keep explanations short; the DDL should carry the detail.
Sample output
## Entity summary
clinics 1--* practitioners 1--* appointments *--1 patients
appointments *--* services (via appointment_services)
## Table definitions
CREATE TABLE patients (
id UUID PRIMARY KEY,
clinic_id UUID NOT NULL REFERENCES clinics(id) ON DELETE RESTRICT,
full_name VARCHAR(200) NOT NULL,
date_of_birth DATE NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
...
## Indexes
-- 'Show a practitioner's appointments for a day'
CREATE INDEX ix_appt_practitioner_start ON appointments (practitioner_id, starts_at);
...
## Key design decisions
1. UUID keys: records are created by mobile clients offline, so ids must be generated outside the database.
2. Appointment price is copied at booking time (deliberate denormalization) so later price changes do not rewrite history...
An example the author shared. Your result will differ.
Reviews
No written reviews yet. If you have used this prompt, tell others how it went.
0 forks
Public forks of “Relational database schema design” by Prompier Library (v1).
Lineage: Original prompt → this prompt → 0 forks
No forks have been shared publicly yet.