Back to Home
Category • 3 Prompts

SQL AI Prompts

SQL prompts for query writing, optimisation, and migration planning. These prompts force the model to explain the query plan and index strategy, not just emit SQL that happens to run.

SQL Prompts

Claude

Here is a slow PostgreSQL query and its EXPLAIN ANALYZE output. Walk the plan node by node, identify the dominant cost, and propose fixes in order of least invasive: query rewrite, then index, then schema change. Estimate the impact of each. Never suggest an index without naming its write cost. [QUERY + PLAN]

▸ ready to run
Claude

Here is a slow PostgreSQL query and its EXPLAIN ANALYZE output. Walk the plan node by node, identify the dominant cost, and propose fixes in order of least invasive: query rewrite, then index, then schema change. Estimate the impact of each. Never suggest an index without naming its write cost. [QUERY + PLAN]

Slow Query Explainer and Fixer

A query-tuning prompt ordered by invasiveness so you try rewrites before adding indexes. Requiring the write-cost caveat on every index suggestion filters out advice that would just move the pain to inserts.

1.2K190
Claude

I want you to act as a SQL terminal in front of an example database. The database contains tables named "Products", "Users", "Orders" and "Suppliers". I will type queries and you will reply with what the terminal would show. I want you to reply with a table of query results in a single code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so in curly braces {like this). My first command is 'SELECT TOP 10 * FROM Products ORDER BY Id DESC'

▸ ready to run
Claude

I want you to act as a SQL terminal in front of an example database. The database contains tables named "Products", "Users", "Orders" and "Suppliers". I will type queries and you will reply with what the terminal would show. I want you to reply with a table of query results in a single code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so in curly braces {like this). My first command is 'SELECT TOP 10 * FROM Products ORDER BY Id DESC'

SQL Terminal for Query Result Rehearsal

Simulates a database terminal that answers with result tables only. Good for sanity-checking join logic, grouping, and window functions against a sample schema before you run anything against real data. Explanations stay suppressed unless you explicitly request them.

33.9K
Claude

Review this schema migration for a production Postgres database under load. Check: lock levels per statement, table rewrite triggers, index build strategy, and rollback path. Output a go/no-go verdict with the exact statement that carries the most risk and a safer sequencing if one exists. [PASTE MIGRATION]

▸ ready to run
Claude

Review this schema migration for a production Postgres database under load. Check: lock levels per statement, table rewrite triggers, index build strategy, and rollback path. Output a go/no-go verdict with the exact statement that carries the most risk and a safer sequencing if one exists. [PASTE MIGRATION]

Migration Plan Reviewer

A pre-deploy gate for schema changes: every statement gets a lock-level check and the riskiest one is named explicitly. The safer-sequencing requirement regularly converts a table-locking migration into a zero-downtime one.

53392