database
Design a normalized SQL schema with indexes and constraints
Turns a plain-language description of your data into a normalized SQL schema with sensible indexes, foreign keys, and constraints.
Who should use this
Is this prompt for you?
- Developers designing a new feature or app's data model from scratch
- Teams that want a schema reviewed for normalization issues before they migrate real data into it
- Anyone unsure which columns need indexes as the dataset grows
The prompt
Copy this prompt
Prompt
Design a SQL schema for the following data, for [PostgreSQL / MySQL / SQLite — specify], to be used with [ORM name, e.g. Prisma/Drizzle/SQLAlchemy, or "raw SQL"]. Data description: [describe your entities and how they relate in plain language, e.g. "users belong to workspaces, workspaces have projects, projects have tasks assigned to users, and tasks can have comments"] Known query patterns: [list the main ways this data will be queried, e.g. "list all tasks for a workspace sorted by due date", "find all comments by a user across projects"] Expected scale: [rough row counts if known, e.g. "thousands of workspaces, tens of thousands of tasks" — or say "unknown, design conservatively"] Please: 1. Propose a normalized schema (tables, columns, types) — call out any deliberate denormalization and why 2. Define primary keys, foreign keys, and ON DELETE behavior (cascade, restrict, set null) for each relationship, with reasoning 3. Add NOT NULL, UNIQUE, and CHECK constraints wherever the data model implies them, rather than relying on application-level validation alone 4. Recommend indexes based on the query patterns I listed, and explain which column(s) each index supports 5. Point out any many-to-many relationships and design the join table properly 6. Write this as an actual migration file (or ORM schema definition) in the format my stack uses 7. Include a couple of example queries for the query patterns I listed, using the schema you designed Flag anything where you had to guess at a business rule (e.g. "can a task exist without a project?") instead of assuming — list these as open questions.
Works well with Claude Code, Cursor and OpenAI Codex.
How to use it
Getting the best result
- 1List your real query patterns, not just your entities — indexing decisions depend entirely on how data gets read
- 2Give an honest scale estimate; a schema for 100 rows and one for 100 million need different tradeoffs
- 3Review the ON DELETE behavior on every foreign key personally — this is where silent data loss happens
- 4Answer the "open questions" the AI flags before running the migration on real data
Expected result
What you should get back
- A normalized schema as an actual migration file or ORM schema definition
- Explicit foreign key relationships with reasoned ON DELETE behavior
- Indexes justified by the query patterns you provided
- A list of business-rule assumptions to confirm or correct
Tips
Get more out of this prompt
- Ask for the schema in your actual ORM's syntax (Prisma schema, Drizzle, SQLAlchemy models) so you can use it directly
- If you already have data, ask for a migration plan separately — schema design and data migration are different risks
- Push back and ask "why" on every index recommendation you don't understand before applying it
Common mistakes
What to watch out for
- Not describing real query patterns, leading to indexes that don't match actual access patterns
- Accepting ON DELETE CASCADE everywhere without considering which relationships should actually block deletion
- Skipping constraints (NOT NULL, UNIQUE, CHECK) and relying only on application code to enforce data integrity
Related prompts
Keep going
saas
Scope and build a SaaS MVP feature end-to-end
Turns a rough SaaS feature idea into a scoped implementation plan and working code, covering data model, backend, UI and edge cases in one pass.
Copy promptapiIntegrate a third-party API with proper error handling and retries
Gets an AI to build a production-grade API client — authentication, retries, rate limiting, and typed responses — instead of a bare fetch call.
Copy promptsecurityRun a focused security review on a feature before shipping
Runs a practical, scoped security review of a specific feature or endpoint — checking auth, input validation, and data exposure before it ships.
Copy promptReady to put this prompt to work?
Pair it with an AI coding tool and a real project, then ship something this week.