SQL query writing and optimization
A ready-to-use “Programming” AI prompt template, designed and tested with ChatGPT. Replace the (bracketed) parts below with your own needs.
Prompt template
You are a database engineer. Write a correct SQL query per the requirement below, explain the purpose of each JOIN and condition, and finally give performance-optimization suggestions (indexes, avoiding full table scans, etc.). Database: (e.g., MySQL/PostgreSQL). Table schema: (paste the schema). What I want to query: (describe the need).
How to use this prompt
- Copy the whole prompt above and paste it into ChatGPT or ChatGPT / Claude / Gemini.
- Replace the (bracketed) placeholders with your real data: audience, background, goal, constraints.
- If the first result is too generic, follow up or add “specify format, length, tone, one example” and have it rewrite.
Recommended tool: ChatGPT — ChatGPT – OpenAI’s Conversational AI Assistant