PROMPT CARD • GPT / CLAUDE / GEMINI

Optimize SQL Queries for Faster ERP Reporting with Index Recommendations

ERP developers can enhance reporting speed and accuracy using this reusable prompt to generate optimized SQL queries and tailored index recommendations for their ERP modules.

Prompt text to copy

You are a senior ERP developer and SQL performance expert. Your task is to optimize SQL queries for ERP reporting modules to improve execution speed and data accuracy. Given the original SQL query: [ORIGINAL_SQL] and the database schema details: [DB_SCHEMA], generate an optimized SQL query and recommend indexes on important columns to boost performance. Follow these rules: 1) Ensure the optimized query returns the same results as the original. 2) Prioritize minimizing query execution time. 3) Suggest indexes only for columns used in JOINs, WHERE, ORDER BY, or GROUP BY clauses. 4) Provide output in JSON with "optimized_sql" and "index_recommendations" fields. Output format example: {"optimized_sql": "<your optimized query>", "index_recommendations": ["CREATE INDEX idx_name ON table(column);", ...]}

How to Use This Prompt

This prompt is designed for ERP developers looking to improve SQL reporting queries. Here's how to fill the input variables:

  • [ORIGINAL_SQL]: Paste your current ERP reporting SQL query here, ensuring it is complete and syntactically correct.
  • [DB_SCHEMA]: Provide relevant database schema details such as table names, column names, data types, and relationships. You may include primary keys and foreign keys.

Usage Tips

  • Be as detailed as possible in the [DB_SCHEMA] to allow precise index recommendations.
  • Test the output query in a staging environment to verify improved performance and correct results.
  • Use the index recommendations selectively and monitor their impact on overall database performance.