Claude SQL Query Prompt with a Fictional Schema and Expected Rows
Draft a SQL query for analysts and developers in Claude: built from the schema you give, plus a check of the result on a small test fixture.
Make it yours
Fill in the inputs. Your prompt updates as you type.
Your prompt
Act as a Senior Data Engineer and Database Administrator. I need you to generate an optimized SQL query based on my natural language request.
Context:
Dialect: {{dialect}}
My Request: {{question}}
Database Schema:
SQL
{{schema}}
Your Task:
Please provide the solution in 3 distinct sections.
Section 1: The Optimized Query
Write the SQL query to answer my request.
Use modern SQL best practices (CTEs over subqueries where appropriate).
Use proper indentation and capitalization (e.g., SELECT, WHERE).
Handle potential edge cases (e.g., NULL values or division by zero).
Section 2: The Logic Breakdown
Briefly explain how the query works in plain English.
Explain the logic behind any Joins, Grouping, or Window Functions used.
Section 3: Performance Check
Recommend one specific Index that would make this query run faster, explaining which columns should be indexed and why.
Output everything in clean Markdown.
Preserve provided facts. Identify missing evidence and assumptions. Do not promise rankings, replies, hiring, perfect fidelity or measured performance without supporting tests.3 inputs still blank. Empty inputs stay as placeholders when copied.
Use it on
Get one tested prompt a week
One workflow, one prompt, one tool and one quality check by email. No spam, unsubscribe any time.
By subscribing you agree to receive this email from Genius Forges and to us storing your address to send it. We may ask you to confirm by email. Every email has an unsubscribe link. See our privacy policy.
Example result
Illustrative example; results vary by input and platform.
How to use this prompt
- 1Supply the SQL dialect, table columns and exact question; use fictional data for the first test.
- 2Check joins, NULL handling and expected totals in a disposable database. Do not execute generated writes against production.
- 3Inspect the query plan before recommending an index; compare the result to an independently calculated expected answer.
Tips & limitations
Editorial example, not a recorded platform test. Use the current model available in your account; no model settings are recommended from an unobserved run.
Explore collections
Did this help you complete your task?
Tell us what needs improving. No account or private output required.
Report incorrect information or a broken linkReview evidence
Illustrative example · 2026-10-07
Illustrative source inputs and reference outputs, not a recorded model benchmark. This example is illustrative. Review the result before using it.