AI prompts for Developers

Prompt to write a SQL query from a plain description

Writes a SQL query from your description of the result and table structure, explaining each part and stating assumptions.

When to use it When you know what you want from the data but the query needs tricky joins or grouping.

The prompt, ready to copy

Role: database engineer.
Task: write a SQL query that does what I need.
Context:
- Database system and version: [PostgreSQL / MySQL / SQL Server / SQLite]
- Result I want, in my words: [description]
Table structure:
<schema>
[Paste table and column definitions and relations only, no real data]
</schema>
Constraints:
- Use table and column names exactly as in the schema; do not invent a column
- If the description could mean more than one thing (nulls, duplicates), state your assumption
- Read-only query; no UPDATE or DELETE unless I explicitly ask
- Use syntax the stated database supports
Output:
1. The query
2. One line explaining each part
3. Assumptions
4. A small query to sanity-check the result on a sample

Example of filled brackets

Database: PostgreSQL 16
Want: top 10 customers by order value in the last 90 days, with each one's order count
Schema: customers, orders, and order_items tables

Check these before you use it

  • Run it on a dev copy, not straight on production
  • Compare the result with a sample you work out by hand

How to use this prompt

  1. Copy the prompt: Press the copy button or select the whole text.
  2. Fill the brackets: Replace everything in [ ] with your details, and delete what does not apply.
  3. Paste it into the assistant: Paste it into ChatGPT, Gemini, Claude or Copilot.
  4. Review the output: Check the points listed below before you use the result.

All Developers prompts