Skip to content

DirectoryPrompts

Claude

Write SQL from a Question

Free
  • Free with an account
  • Copy or download
  • Updates included

By downloading this prompt, you agree to our Terms of service.

votes views

Claude Opus 5.5

This prompt turns a plain question into SQL. Paste your database type, the schema and your question; you get the definitions it used, the query, how it works and quick checks on the result.

What Write SQL from a Question gives you

What you get

  • The exact rule it used for each vague word, such as last 90 days or customer
  • One read-only query for your database, with comments on the joins and filters
  • A plain explanation of how the query works, in the order it runs
  • Quick checks to confirm the numbers before you use them

How to use it

  1. 1Paste the schema Copy the CREATE TABLE statements or a list of columns, and add what status or type values mean.
  2. 2Ask as you would ask a colleague Include what to leave out, how to sort and the time range, in plain words.
  3. 3Run the checks first Read the definitions, run the check queries, and only then use the numbers in a report.

Tips

  • Add a few sample rows when values are messy, such as mixed status spellings, so the filters match the real data.
  • If a definition is wrong, correct it in one line, such as "active means logged in within 30 days", and ask for the query again.
  • Run a new query on a replica, or with a LIMIT, before you run it on large production tables.

Reviews

No reviews yet

  • Only signed-in readers can review
  • One review per person
  • Never paid for

Frequently Asked Questions

Can ChatGPT write SQL queries?

Yes, ChatGPT writes good SQL when you paste the schema and name your database, such as PostgreSQL or MySQL. Without the schema it guesses table and column names, so always give it the real ones and check the joins.

How do I turn a question into SQL with AI?

Paste the schema, name your database and ask the question in plain words, including filters and the time range. Ask the AI to state how it defined vague words like active or revenue, then run a quick check before you trust the numbers.

Is AI-generated SQL safe to run?

AI-generated SQL is safe to run when it is a read-only SELECT and you have read it first. Ask for read-only queries, check any UPDATE or DELETE line by line before running it, and test heavy queries on a copy or replica.

Similar Prompts

More Coding Prompts

Image Prompts

Video Prompts

Trending Prompts

Newest Prompts

Browse all prompts