Home/Templates/Database Schema
Coding

Database Schema Prompt Template

Design a normalised database schema with table definitions, relationships, indexes, and query optimisation notes.

The Prompt

ROLE: You are a database architect with experience designing schemas for high-traffic production applications — you design for query performance from day one, not as an afterthought. CONTEXT: You are designing a database schema for an application. The schema must be correctly normalised to prevent data anomalies, but also practical — over-normalisation kills developer velocity. Every index must be justified by an actual query pattern, not added speculatively. TASK: Design a complete database schema for the application described below, including tables, relationships, indexes, and example queries. RULES: • Every table must have a primary key and a created_at / updated_at timestamp • Foreign key relationships must explicitly state the ON DELETE behaviour (CASCADE, SET NULL, RESTRICT) with justification • Each index must name the specific query it optimises — no unexplained indexes • If any design decision trades normalisation for performance (e.g. a denormalised field), flag it with [DENORM:] and explain the reasoning • Include 3 example queries that demonstrate the schema in use, covering the most common read patterns CONSTRAINTS: Use [POSTGRES/MYSQL/MONGODB] syntax. All column names in snake_case. Data types must be specific (varchar(255) not varchar; timestamptz not timestamp for Postgres). Comments on non-obvious column purposes. EDITABLE VARIABLES: • [APPLICATION] — what the application does and its core domain entities • [DATABASE] — Postgres / MySQL / MongoDB / other • [SCALE] — approximate row counts for the largest tables (affects index strategy) • [QUERY_PATTERNS] — the 3 most frequent read queries this schema must support efficiently OUTPUT FORMAT: ```sql -- Table definitions with column types, constraints, comments -- Foreign key relationships with ON DELETE behaviour -- Index definitions with justification comments ``` **Entity Relationship Summary:** [Table] → [Table]: [relationship type and cardinality] **Example Queries:** ```sql -- Query 1: [description] [SQL] ``` **[DENORM:] notes** [Any deliberate denormalisation decisions] QUALITY BAR: Running EXPLAIN ANALYZE on the 3 example queries should produce sequential scans only on tables where full scans are acceptable, and index scans everywhere else.

Make it specific to you

PromptITIN asks a few questions and builds a version tailored to your use case.

✦ Enhance with AI

How to use this template

1

Copy the template

Click the copy button to grab the full prompt text.

2

Fill in the placeholders

Replace anything in [BRACKETS] with your specific details.

3

Paste into any AI tool

Works with ChatGPT, Claude, Gemini, Cursor, and more.

4

Or enhance with AI

Sign in to PromptITIN and let AI tailor the prompt to your exact situation in seconds.

Why this prompt works

Requiring ON DELETE behaviour to be stated and justified is the most important safety rule in schema design — implicit cascade deletion is one of the most common causes of production data loss. Tying each index to a named query prevents index sprawl that slows writes.

Tips for best results

  • Give the AI your 3 most important dashboard queries before designing the schema — working backwards from reads produces better-indexed schemas than designing top-down
  • The ON DELETE decision for your most critical foreign keys should be a human decision — ask the AI to list them and explain each option before accepting its defaults
  • Add 'use UUIDs for all primary keys' or 'use integer sequences' to CONSTRAINTS based on your specific needs — this changes the joins strategy significantly
  • Run EXPLAIN on the generated example queries after implementing — if the AI's index suggestions don't get picked up by the planner, there's usually a type mismatch or missing cast

More Coding templates

Code Review

Get a comprehensive AI code review covering bugs, performance issues, security vulnerabilities, best practice violations, and refactoring opportunities with specific line references.

View →

Debug an Error

Diagnose any code error with a structured breakdown: root cause analysis, step-by-step fix, and prevention strategies for the future.

View →

Explain Code Simply

Translate complex code into plain English with line-by-line explanations, real-world analogies, and edge-case analysis for any skill level.

View →
← Browse all 195 templates