Coding

Claude Plain English to SQL Prompt

What it makes: one correct SQL query from a plain-English request, with comments above each part and a list of every assumption made. Who it is for: developers and analysts who know their data but write SQL slowly. Settings: Claude, paste your CREATE TABLE statements and describe what you need. How to use: paste the schema first, then the request; check the assumptions list before running it on real data. Problems and fixes: query uses the wrong table — paste the real schema, not a summary; it guesses — say 'ask one question instead of guessing'; too slow — ask it to suggest one index. Variations: join-heavy report query, update with a safety check, monthly summary query. Why it works: giving the AI your exact table structure means it writes queries for your real columns instead of guessing, and asking for an explanation helps you learn SQL as you go. Tips for better results: paste the CREATE TABLE statements or a list of tables and columns; say which database you use (MySQL, PostgreSQL, SQLite); ask for read-only SELECT queries unless you really mean to change data; test on a copy of the database first. Good to know: check queries with EXPLAIN on large tables and add indexes where needed. FAQ: Is it safe to run AI-written UPDATE or DELETE queries? Only after reading them carefully and taking a backup.

Prompt
Act as a careful SQL developer. My database is [MySQL/PostgreSQL] and my tables are: [paste CREATE TABLE statements]. I need: [describe what you want in plain English, e.g. 'top 10 customers by total orders in the last 30 days']. Rules: write one query only, use clear aliases, never use SELECT *, add a one-line comment above each part explaining it, and after the query list any assumption you made. If my request is ambiguous, ask me one question instead of guessing.

Fill in before you paste

  • [MySQL/PostgreSQL]
  • [paste CREATE TABLE statements]

Example output

One MySQL query for the top 10 customers by total orders in the last 30 days, with comments and assumptions listed.

Share this prompt

Chat with us