WorkflowFor DevelopersCode Writing & Debugging

Database Schema & Query Optimisation.

When designing or auditing a database layer for a new or growing system.

ChatGPT Β· Claude Β· GeminiΒ·AdvancedΒ·~1950 tokens
Curated by the AIPP team
Last updated 14 May 2026 Β· v3
database-schema-query-optimisation-4.md Β· 1950 words
You are a senior {{role}} brought in to help a developer or tech professional complete a {{use_case}} task.

# Context
- Pack: Developers & Tech Professionals
- Category: Code Writing & Debugging
- Use case: Database Schema & Query Optimisation
- Source task:
  - I need to optimise the database layer for {{describe_system}}.
  - Step 1: Schema Design: Design a normalised schema for {{entities_and_relationships}}, with index recommendations and data type choices explained.
  - Step 2: Query Writing: Write optimised SQL (or NoSQL equivalent) for the top 5 most common queries: {{list_queries}}.
  - Step 3: Performance: Identify N+1 query risks, missing indexes, and any queries that will not scale beyond 1M rows, with fixes for each.

# Goal
A schema design, 5 optimised queries, and a performance audit covering N+1 risks, index gaps, and scalability issues.

# Constraints
- Treat this as a sequential workflow where each step builds on the previous step.
- Keep every step clearly labeled and easy to run separately if needed.
- Avoid generic filler, vague advice, and unsupported claims.
- Make the output specific, practical, and ready to use.

# Output
A schema design, 5 optimised queries, and a performance audit covering N+1 risks, index gaps, and scalability issues.

The variables to fill in

PlaceholderWhat to put thereExample
{{role}}Roledatabase architect
{{use_case}}Your specific valuedatabase schema & query optimisation
{{describe_system}}Describe systemExample describe system
{{entities_and_relationships}}Entities and relationshipsusers, orders, payments, subscriptions
{{list_queries}}List queriestop customers, daily revenue, failed payments, active subscriptions, churned accounts

How to customize this prompt

  1. Replace each {{double-curly}} with your real context.
  2. Adjust the constraints section to match your tone β€” formal, casual, blunt.
  3. If the engagement is recurring, change the duration line to mention milestones rather than days.
  4. Run it in your tool of choice. The output should be ready to paste with at most one small edit.

When to use

When designing or auditing a database layer for a new or growing system.

PRO TIP

Add an EXPLAIN ANALYZE output for any slow query β€” AI can read execution plans and identify the exact bottleneck in seconds.

Related prompts

Structured

Technical Problem Debugger

Debug this problem systematically. Identify the root cause, explain why it is happening, provide the fix, and explain how to prevent it in future.

Structured

System Design Advisor

Design the high-level architecture for this system. Cover components, data flow, scaling strategy, and key design decisions.

Structured

No-Code Tool Selector

Recommend the best no-code or low-code tool stack for the stated goal, with implementation guidance.

Structured

Data Analysis Prompt

Design the complete analysis approach for the stated question. Include the analytical method, the steps to execute it, and the format for presenting findings.

β˜… THIS PROMPT IS IN A PACK

The Developer Toolkit Pack

250 technical prompts for code review, documentation, architecture planning, debugging, test writing, API design, and career growth β€” built by developers for developers.

Browse more prompts β†’