{"name":"write-sql-from-plain-english-prompt","description":"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.","category":"coding-prompts","tags":["sql","database"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/write-sql-from-plain-english-prompt","api_url":"https://theskillvault.ai/api/skills/write-sql-from-plain-english-prompt","raw_url":"https://theskillvault.ai/api/skills/write-sql-from-plain-english-prompt/raw","body":"# Write SQL from plain English (prompt)\n\nDescribe the data you want and get a query you can read and trust, for your actual tables.\n\n## When to use\n- You know what data you want but not how to write the SQL.\n- You want a report: sign-ups per week, top customers, unpaid invoices.\n- You want a first draft of a tricky join or group-by.\n\n## When not to use\n- A query works but is slow. Use optimise-slow-sql-queries.\n\n## Steps\n1. Get your schema: table names, columns and how tables link. In Postgres, `\\d tablename` shows it; most tools can export it.\n2. Fill in {{DATABASE}} (PostgreSQL, MySQL, SQLite, SQL Server) and your question.\n3. Paste the prompt and run the query on a copy or with a `LIMIT` first.\n4. Check a few rows by hand before you rely on the numbers.\n\n## Prompt\n```text\nWrite a SQL query for {{DATABASE}}.\n\nQuestion: {{WHAT YOU WANT, IN PLAIN ENGLISH}}\n\nSchema:\n{{TABLES, COLUMNS, KEYS}}\n\nRules:\n1. 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.\n2. List columns explicitly; no SELECT *.\n3. Use short, clear table aliases and explicit JOIN ... ON.\n4. Handle NULLs and time zones deliberately, and say how.\n5. Add LIMIT for exploratory queries.\n\nThen give me:\n- A plain-English explanation of what the query returns.\n- Assumptions you made about the schema or the question.\n- Two checks to confirm the result is right (for example a row count or a known value).\n```\n\n## How to adapt\n- Using an ORM? Add \"also show the Prisma (or Drizzle) version\".\n- Building a dashboard? Ask for a query per metric with the same date filter.\n\n## Gotchas\n- Never paste production passwords, connection strings or real customer rows into an AI tool. Column names are enough.\n- Run generated writes inside a transaction you can roll back, and back up first.\n- Wrong joins quietly double-count. Check totals against a number you already know.\n\n## Portability\nWorks with any SQL database and any chat AI or coding agent. No tool lock-in.\n\n## Done when\n- The query runs and returns what the question asked.\n- You checked the result against at least one known number.\n\n## Example prompt\n\"Using my orders and customers tables in Postgres, write a query for the top 10 customers by total spend in the last 90 days.\"\n\n---\nBased on the \"SQL Query Generator from Natural Language\" prompt by a prompts.chat contributor (CC0 1.0, public domain).","files":[],"license":"CC0-1.0","license_name":"CC0 1.0","license_url":"https://creativecommons.org/publicdomain/zero/1.0/","attribution":"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","install":{"claude_code":"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":"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'","agents":"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'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-02T03:20:33.817Z"}}