SQL Query Writer With Schema Check
Writes correct SQL from plain English, states assumptions about your schema and explains performance.
The prompt
Remixed ·Fill in the variables
The prompt above updates live. Nothing leaves your browser.Remix it
One-click variations. Stack them, then copy.
Why this prompt works
The "only use what exists" rule is the single biggest fix for hallucinated columns. CTEs make the logic auditable, and the plain-English explanation lets you sanity-check the query against what you actually asked for.
Framework: RTF. Role, Task, Format: the simplest reliable structure.
Example
Illustrative, not a real model outputExample input
- [SQL_DIALECT]
- PostgreSQL
- [PLAIN_ENGLISH_REQUEST]
- monthly revenue by plan for 2026, only paid invoices
- [TABLE_DEFINITIONS]
- invoices(id, customer_id, plan, amount_cents, status, paid_at)
What a good answer looks like (abridged)
How to use it
- Fill in 3 variables below (or in the prompt) with specific details.
- Paste it into ChatGPT (also works in Claude, Gemini, Grok).
- Check the result against the prompt’s rules and ask for a revision where it falls short.
ChatGPT tips
- Put the output format (schema, table columns) near the top: ChatGPT follows explicit structure very reliably.
- Use a Project or custom instructions for prompts you reuse daily.
Common mistakes
- Leaving [VARIABLES] unfilled or vague ("my business") instead of specific ("a 3-person Calgary bakery").
- Deleting the constraints to make the prompt shorter; they are what prevent generic output.
- Accepting the first answer. Reply with what to fix and ask for a revision.
Guide: Promptnic template.
Frequently asked questions
Which AI model works best with the SQL Query Writer With Schema Check prompt?+
It is tuned for ChatGPT and also works in Claude, Gemini, Grok, DeepSeek. Put the output format (schema, table columns) near the top: ChatGPT follows explicit structure very reliably.
How do I use this prompt?+
Copy it, replace the 3 [VARIABLES] (sql dialect, plain english request, table definitions) with your details, then paste it into ChatGPT. You can fill the variables on this page and copy the finished version.
Is this prompt free to use?+
Yes. Every prompt on Promptnic is free to copy, adapt and use in personal or commercial work. A link back is appreciated, not required.
Why does this prompt work?+
The "only use what exists" rule is the single biggest fix for hallucinated columns. CTEs make the logic auditable, and the plain-English explanation lets you sanity-check the query against what you actually asked for.
Related prompts
Strict JSON Extractor With Self-Check
Pulls structured data out of messy text into an exact JSON schema, with nulls instead of made-up values.
Performance Detective
Finds the real bottleneck in slow code or queries, estimates impact and proposes fixes ranked by effort.
README That Gets People to Try Your Project
Writes a README with a one-line pitch, quick start that works on the first try, and honest limitations.
Tests That Actually Catch Regressions
Generates a focused test suite around behaviour, edge cases and failure modes instead of shallow coverage padding.
Error Message Translator
Explains a cryptic error in plain English, lists likely causes for your setup and gives the fix commands.
Regex Builder With Test Cases
Builds a regular expression from plain English and proves it with matching and non-matching examples.