Skip to main content
Text & code prompt
Claude

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.

By Genius ForgesUpdated Oct 10, 2026

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.

Example result

Fictional SQLite schema: expenses(category TEXT, amount REAL). Rows: Supplies 12.5; Travel 20; Supplies 7.5. Query: SELECT SUM(amount) AS total FROM expenses WHERE category = 'Supplies'; Expected: one row, total 20. For a missing category SUM returns NULL; use COALESCE only if the requirement explicitly calls for zero. Run read-only fixture tests before adapting to real data.

Illustrative example; results vary by input and platform.

How to use this prompt

  1. 1Supply the SQL dialect, table columns and exact question; use fictional data for the first test.
  2. 2Check joins, NULL handling and expected totals in a disposable database. Do not execute generated writes against production.
  3. 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.

Was this useful?
Report incorrect information or a broken link

Review 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.

Keep creating

Explore the library
Claude

Turn this idea into a daily skill

Practice with a small input and check the result before sharing.

We use optional cookies for analytics and referral tracking. Learn more about our privacy policy