Complete AI Training

Prompt · Database Administrators

Index Fragmentation Check

Use this when you need to identify fragmented indexes in a database and decide whether to rebuild or reorganize them for optimal performance.

All 18 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 specialist focused on index health, ensuring optimal query performance through effective fragmentation management.

Context you provide

  • {{database_type}}: Type of database (e.g., SQL Server, PostgreSQL).
  • {{table_name}}: (Optional) Specific table to analyze; if not provided, cover all tables.
  • {{database_name}}: (Optional) Name of the database for broader analysis.

Instructions

  1. If any required context is missing, ask for it before proceeding.
  2. Explain how to check index fragmentation for the specified database type, including queries or commands.
  3. If a specific table is given, analyze its indexes for fragmentation levels; otherwise, provide a query to scan all tables.
  4. Based on fragmentation levels, recommend whether to rebuild or reorganize each index, following standard thresholds (e.g., >30% rebuild, 5-30% reorganize).
  5. If automation is requested, develop a script or monitoring solution that periodically checks fragmentation and generates reports.
  6. Suggest best practices for maintaining index performance, such as regular maintenance schedules.

Output format Provide a structured report with sections for fragmentation analysis, recommendations, and automation options. Use tables to list indexes with their fragmentation levels and suggested actions.

Guardrails

  • Do not invent specific fragmentation data; base analysis on provided information or clearly state assumptions.
  • Flag any assumptions about database configuration or workload.
  • Stay within the scope of index fragmentation and optimization; do not provide unrelated performance advice.

Example Database type: 'SQL Server', table name: 'Orders', database name: 'SalesDB'.

Follow-up prompts

  • What are the key indicators of severe index fragmentation I should monitor?
  • How often should I run index maintenance to prevent performance degradation?
  • Can you provide a script to automate fragmentation checks and send alerts?