Coding prompts · Prompt

Write SQL from plain English (prompt)

write-sql-from-plain-english-prompt

A prompt that writes a SQL query from a plain-English question - a correct, readable query for your database and schema - explicit columns, clear joins and filters, read-only by default - and explains what it returns and what to double-check. Use when the user needs a SQL query written, asks how to get some data out of their database, or does not know SQL.

Works with: Any AI Not yet model-tested; testing Jan 2027

Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works

Install in Claude Code, Cursor or Codex (optional)

Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.

Claude Code (all your projects)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-sql-from-plain-english-prompt/raw' -o ~/'.claude/skills/write-sql-from-plain-english-prompt/SKILL.md'

Cursor (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-sql-from-plain-english-prompt/raw' -o '.cursor/skills/write-sql-from-plain-english-prompt/SKILL.md'

Codex and other Agent Skills tools (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-sql-from-plain-english-prompt/raw' -o '.agents/skills/write-sql-from-plain-english-prompt/SKILL.md'

Or connect the whole library over MCP

Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):

{
  "mcpServers": {
    "theskillvault": {
      "url": "https://theskillvault.ai/mcp"
    }
  }
}

Describe the data you want and get a query you can read and trust, for your actual tables.

When to use

  • You know what data you want but not how to write the SQL.
  • You want a report: sign-ups per week, top customers, unpaid invoices.
  • You want a first draft of a tricky join or group-by.

When not to use

  • A query works but is slow. Use optimise-slow-sql-queries.

Steps

  1. Get your schema: table names, columns and how tables link. In Postgres, \d tablename shows it; most tools can export it.
  2. Fill in {{DATABASE}} (PostgreSQL, MySQL, SQLite, SQL Server) and your question.
  3. Paste the prompt and run the query on a copy or with a LIMIT first.
  4. Check a few rows by hand before you rely on the numbers.

Prompt

Write a SQL query for {{DATABASE}}.

Question: {{WHAT YOU WANT, IN PLAIN ENGLISH}}

Schema:
{{TABLES, COLUMNS, KEYS}}

Rules:
1. Read-only: use SELECT only. If the question needs INSERT, UPDATE or DELETE, show it separately with a warning and a WHERE clause, and never include DROP or TRUNCATE.
2. List columns explicitly; no SELECT *.
3. Use short, clear table aliases and explicit JOIN ... ON.
4. Handle NULLs and time zones deliberately, and say how.
5. Add LIMIT for exploratory queries.

Then give me:
- A plain-English explanation of what the query returns.
- Assumptions you made about the schema or the question.
- Two checks to confirm the result is right (for example a row count or a known value).

How to adapt

  • Using an ORM? Add "also show the Prisma (or Drizzle) version".
  • Building a dashboard? Ask for a query per metric with the same date filter.

Gotchas

  • Never paste production passwords, connection strings or real customer rows into an AI tool. Column names are enough.
  • Run generated writes inside a transaction you can roll back, and back up first.
  • Wrong joins quietly double-count. Check totals against a number you already know.

Portability

Works with any SQL database and any chat AI or coding agent. No tool lock-in.

Done when

  • The query runs and returns what the question asked.
  • You checked the result against at least one known number.

Example prompt

"Using my orders and customers tables in Postgres, write a query for the top 10 customers by total spend in the last 90 days."

---

Based on the "SQL Query Generator from Natural Language" prompt by a prompts.chat contributor (CC0 1.0, public domain).

Licence

Adapted from A prompts.chat contributor ('SQL Query Generator from Natural Language') (Public domain (CC0 1.0) - prompt contributed to prompts.chat by a prompts.chat contributor), CC0 1.0. Adapted by TheSkillVault: rewrote the structured JSON prompt as a fill-in prompt with schema, dialect and read-only rules, an explanation and a sanity-check section; added steps, adapt notes, safety and done-when.

Licence: CC0 1.0. Attribution when you reuse it: Based on work by A prompts.chat contributor ('SQL Query Generator from Natural Language') (Public domain (CC0 1.0) - prompt contributed to prompts.chat by a prompts.chat contributor, CC0 1.0), https://github.com/f/prompts.chat/blob/b09880e229d2f091ffa2254bc187532fb8980f9b/prompts.csv; adapted by TheSkillVault, https://theskillvault.ai