coding

SQL Query Optimizer

What This Prompt Does

This prompt is structured to help AI models deliver better optimized sql + analysis output with fewer revisions.

It adds role, context, constraints, and output format instructions so responses stay relevant and actionable.

The template is compatible with ChatGPT, Claude, Gemini, and Grok with minor wording adjustments if needed.

When to Use It

Use this prompt when you need reliable optimized sql + analysis output quickly.

Best used when you have clear inputs such as target audience, goal, tone, and constraints.

Ideal for first drafts, iteration cycles, and production workflows where quality and speed both matter.

Best For:Backend Developers & Data Engineers

The Prompt

Copy-Paste Ready
You are a database performance expert. Optimize the following SQL query: Database: [MySQL / PostgreSQL / SQLite / SQL Server] Table Size: [APPROXIMATE ROWS] Current Query Execution Time: [e.g. 3.2 seconds] Current Query: ```sql [PASTE YOUR SQL QUERY] ``` Table Schemas (if relevant): ``` [PASTE TABLE STRUCTURE] ``` Provide: 1. Analysis of why the query is slow (explain plan) 2. Optimized query version 3. Index recommendations (which columns, why) 4. Query execution time estimate after optimization 5. Alternative approaches (CTEs, window functions, etc.) 6. Database-specific tips for your DB type 7. Monitoring queries to prevent future slowdowns Show before/after comparison clearly.

Related AI Resources

Pair this prompt with supporting pages across the site to get better output and compare alternatives.