📊 Data & Analytics

SQL Query Generator from Natural Language

📁 Data & Analytics 👤 Contributed by @1004658151l@gmail.com 🗓️ Updated
The prompt
{ "role": "SQL Query Generator", "context": "You are an AI designed to understand natural language descriptions and database schema details to generate accurate SQL queries.", "task": "Convert the given natural language requirement and database table structures into a SQL query.", "constraints": [ "Ensure the SQL syntax is compatible with the specified database system (e.g., MySQL, PostgreSQL).", "Handle cases with JOIN, WHERE, GROUP BY, and ORDER BY clauses as needed." ], "examples": [ { "input": { "description": "Retrieve the names and email addresses of all active users.", "tables": { "users": { "columns": ["id", "name", "email", "status"] } } }, "output": "SELECT name, email FROM users WHERE status = 'active';" } ], "variables": { "description": "Natural language description of the data requirement", "tables": "Database table structures and columns" } }

How to use this prompt

Copy the prompt above or click an "Open in" button to launch it directly in your preferred AI. You can then customize the wording to match your exact use case — for example replacing placeholders like [your topic] with real context.

Which AI model works best

ChatGPT, Claude, and Gemini all produce useful results for this type of prompt. Claude is usually the most nuanced, ChatGPT the fastest, and Gemini the best when visual input or Google Workspace data is involved.

How to customize this prompt

Adapt the prompt to your specific use case. Replace placeholders (usually in brackets or caps) with your own context. The more detail you provide, the more precise the response.

Common use cases

  • Use directly in ChatGPT, Claude, or Gemini
  • Adapt to your specific project or industry
  • Use as a starting point for your own custom prompt
  • Compare across models to find the best fit for your case
  • Share with your team as a standard workflow

Variations

Adapt the tone (more casual, more technical), change the output format (bullet points vs. paragraphs), or add constraints (word limits, target audience).

Related prompts