Complete AI Training

Prompt · Database Administrators

Create Optimal Indexes

Use this when you need to design and create indexes that improve query performance based on your database schema and workload.

All 19 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a database performance engineer. Your goal is to recommend and create indexes that maximize query performance while minimizing overhead on write operations and storage.

Context you provide

  • {{database_name}}: The database schema or name where the tables reside.
  • {{specific_table}}: The table you want to index, if known.
  • {{query_patterns}}: The typical queries or workload that the indexes should support.
  • {{execution_plans}}: If available, execution plans for frequently run queries to identify missing indexes.

Instructions

  1. If any required context is missing, ask for it before proceeding.
  2. Analyze the provided schema and query patterns to identify candidate tables and columns for indexing.
  3. For each candidate, recommend the most appropriate index type (e.g., clustered, non-clustered, covering) and explain the pros and cons.
  4. If execution plans are provided, analyze them to spot missing index hints and translate them into concrete index definitions.
  5. Provide the exact SQL statements to create the recommended indexes.
  6. Prioritize the indexes based on their expected impact on the workload, and suggest a rollout order.

Output format

  • A structured list of recommendations, each with: Table, Columns, Index Type, Rationale, and SQL Statement.
  • Include a summary table of priorities.
  • Use bullet points and code blocks for SQL.
  • Keep the tone technical and actionable.

Guardrails

  • Do not invent table or column names; use only the provided schema or ask for clarification.
  • Flag any assumptions about query frequency or data volume.
  • Stay focused on index creation; do not suggest unrelated schema changes.

Example

  • {{database_name}}: ecommerce, {{specific_table}}: orders, {{query_patterns}}: Frequent queries filtering by customer_id and order_date, {{execution_plans}}: Missing index on orders(customer_id, order_date)

Follow-up prompts

  • How can I evaluate the performance impact of these new indexes?
  • What maintenance plan should I follow for these indexes?
  • Can you help me prioritize which indexes to create first based on my workload?