We loaded a file of 4,734 invented orders into DuckDB, wrote five plain-English business questions, and had Claude write the SQL for each one twice: once from the question alone, once with the table's schema pasted in. Then we ran all ten queries and checked every answer against the same numbers computed in pandas. The results, the SQL and the prompt are below, followed by six free generators described from their own pages.
The short answer: an AI SQL query generator uses a language model to turn a question into SQL, and the model only knows your tables if you give it their names, columns and types. In our test, Claude's SQL from the question alone failed all five times, on tables that don't exist; with the CREATE TABLE statement pasted in, all five ran and four matched pandas. The fifth compared 10 months of 2026 with all of 2025. Free options: the ChatGPT and Claude free plans (you paste the schema), and Gemini in BigQuery, Supabase's assistant, DBeaver Community and Vanna, which work on your database directly. Checked 1 December 2026.
Fastero
Connect your database. Ask questions. Get dashboards.
Postgres, BigQuery, Snowflake, and 10+ sources — live-connected, AI-powered, no dashboard builder learning curve.
Try free →How does an AI SQL query generator work?
Whether it's sold as an AI SQL generator, an AI SQL builder or text-to-SQL, the core is the same. A language model has read a great deal of SQL, so given a question it writes the SQL that most plausibly answers it. What it hasn't seen is your database. Unless the tool hands it your table and column names, it writes SQL for an imaginary database: a table called orders, a column called customer_id, whatever is most common in the SQL it learned from.
Tools get the schema to the model in one of three ways:
- You paste it in. General chatbots such as ChatGPT and Claude know only what you type or upload.
- The tool reads it from your connection. Database tools send the model your table and column names with each question. DBeaver's wiki says "By default, only table and column names are sent to AI provider"; Supabase says "No data is sent to the underlying LLM, only your schema structure"; Text2SQL.ai says "Only schema names are sent to AI Providers."
- The tool retrieves it. Retrieval-based tools store your table definitions, documentation and past queries and pick the relevant pieces for each question; Vanna, for one, lets you add "RAG, memory, or documentation" to its agent.
The schema tells the model what exists. It doesn't say what your words mean (does revenue include refunds?), which values a column holds, or which dates the data covers. Our test hit the last one.
What to paste into an AI SQL generator
- The database and version: DuckDB, PostgreSQL 16, BigQuery. Date functions and
LIMITdiffer between them. - The schema: a
CREATE TABLEstatement or the output ofDESCRIBE, for every table the question touches, with the join keys. - A few sample rows, or the distinct values of text columns such as region or status.
- The date range the data covers. This would have fixed the one wrong answer in our test.
- What your business words mean: which orders count as revenue, what an active customer is.
- A request to state its assumptions, so you can see where it guessed.
To get the schema and the date range out of your database:
-- DuckDB
DESCRIBE sales;
-- PostgreSQL, MySQL and SQL Server
-- (in BigQuery, query your_dataset.INFORMATION_SCHEMA.COLUMNS)
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_name = 'sales'
ORDER BY ordinal_position;
-- What the data covers
SELECT count(*), min(order_date), max(order_date) FROM sales;A prompt with all of that in it:
Write a DuckDB SQL query that answers: How much did revenue grow in 2026
compared with 2025?
Schema:
CREATE TABLE sales (order_id BIGINT, order_date DATE, region VARCHAR,
channel VARCHAR, segment VARCHAR, category VARCHAR, product VARCHAR,
quantity BIGINT, unit_price DOUBLE, revenue DOUBLE);
One row per order. revenue = quantity * unit_price.
The data runs from 2024-11-01 to 2026-10-31.
List any assumptions you make.We tested it: five questions, with and without the schema
The data is the sample file every new Fastero workspace starts with: 4,734 invented orders from 1 November 2024 to 31 October 2026, one row per order, with region, channel, segment, category, product, quantity, unit price and revenue. None of it is real. We loaded it into DuckDB 2.0.1 in a Python 3.14 virtual environment on Windows.
The five questions, as a business user would type them:
- What was our total revenue in 2025?
- What are our five best-selling products by revenue?
- What is the average order value for each sales channel?
- How much did revenue grow in 2026 compared with 2025?
- Who are our top 10 customers by revenue?
The fifth is a trap: the table has no customer column, so the right answer is to say so.
The SQL was written by Claude (Anthropic's model, Opus 5.5), not by us. Each set of five ran in a fresh session with no tools and no files, given only the prompts and an instruction to answer each question as if in its own chat, with SQL and at most two sentences of notes. For every question the prompt was this, with the question at the end:
Write a DuckDB SQL query that answers this question:The second run added Here is my table's schema: and the CREATE TABLE statement above. We ran all ten queries and compared each result with the same figure computed in pandas 3.1.2 from the same file.

Ten queries written by Claude, run in DuckDB on invented data and checked against pandas, 1 December 2026.
Without the schema, none of the five ran
Every query from the question alone named a table that doesn't exist. This is Claude's answer to question 2:
SELECT
product_name,
SUM(quantity * unit_price) AS revenue
FROM order_items
GROUP BY product_name
ORDER BY revenue DESC
LIMIT 5;Catalog Error: Table with name order_items does not exist!The answers weren't careless. Four of the five came with a note naming the table and columns they assumed, and the first asked us to rename them to match ours. So we tried exactly that: we changed only the table name, to sales, and ran them again. Two then ran: question 1 gave the right total, and question 4 gave the same misleading figure as the schema run below. The other three failed on columns it had invented: product_name, sales_channel and customer_id. A generator without your schema hands you a template to fix, not a query.
With the schema, four right and one misleading
With the schema pasted in, all five ran. Total revenue for 2025 came to $695,176.98, exactly the pandas figure; the five products and the three channel averages matched to the cent. Question 4 is the interesting one:
WITH yearly AS (
SELECT
SUM(revenue) FILTER (WHERE year(order_date) = 2025) AS revenue_2025,
SUM(revenue) FILTER (WHERE year(order_date) = 2026) AS revenue_2026
FROM sales
)
SELECT
revenue_2025,
revenue_2026,
revenue_2026 - revenue_2025 AS revenue_growth,
ROUND(100.0 * (revenue_2026 - revenue_2025) / revenue_2025, 2) AS growth_pct
FROM yearly; revenue_2025 revenue_2026 revenue_growth growth_pct
695176.98 692051.06 -3125.92 -0.45The SQL is correct for the question as asked, and the answer is wrong for the business. The data stops on 31 October 2026, so this compares 10 months of 2026 with 12 of 2025 and reports a small fall. On the same months of both years, revenue grew 21.31%. Claude's note under the query warned that a part-year would skew the comparison, but the schema couldn't tell it the data ends in October. Checking takes two steps. We ran this in the same environment:
import duckdb
import pandas as pd
con = duckdb.connect()
con.sql("CREATE TABLE sales AS SELECT * FROM read_csv_auto('sample-sales.csv')")
# 1. What the data covers: paste this into the prompt along with the schema
print(con.sql("SELECT count(*) AS orders, min(order_date) AS first, max(order_date) AS last FROM sales"))
# 2. Q4 checked in pandas, on the same months of both years
df = pd.read_csv("sample-sales.csv", parse_dates=["order_date"])
jan_oct = df[df.order_date.dt.month <= 10]
by_year = jan_oct.groupby(jan_oct.order_date.dt.year).revenue.sum()
print(f"Jan-Oct 2025: {by_year[2025]:,.2f} Jan-Oct 2026: {by_year[2026]:,.2f} "
f"growth: {(by_year[2026] / by_year[2025] - 1) * 100:+.2f}%")┌────────┬────────────┬────────────┐
│ orders │ first │ last │
│ int64 │ date │ date │
├────────┼────────────┼────────────┤
│ 4734 │ 2024-11-01 │ 2026-10-31 │
└────────┴────────────┴────────────┘
Jan-Oct 2025: 570,498.20 Jan-Oct 2026: 692,051.06 growth: +21.31%The question the table can't answer
Without the schema, Claude grouped by customer_id and customer_name. With it, Claude said the table has no customer column, ranked the three customer segments instead and asked for a customer table. That is the right answer, and the most useful thing the schema bought: a generator that knows what's missing stops inventing it.
Connect any database. Ask in plain English.
Start free →Free AI SQL query generators compared
Each described from its own pages on 1 December 2026. We tested only Claude, above; the rest we haven't run.
| Tool | Free part | Where it gets your schema | Paid plans |
|---|---|---|---|
| ChatGPT | Free plan | You paste it, or upload a file | Go, Plus and Pro |
| Claude | Free plan | You paste it, or upload a file | Pro from $17 a month yearly, $20 monthly |
| Gemini in BigQuery | SQL generation at no extra cost in BigQuery | Reads your BigQuery metadata | You pay for BigQuery compute |
| Supabase AI Assistant | In the dashboard; Supabase's Free plan is $0 | Reads your Postgres schema | Supabase Pro from $25 a month |
| DBeaver Community | Free, open-source desktop client | Reads table and column names from the connection | Your AI provider's charges |
| Vanna | Open-source Python library (MIT) | Its SQL tool on your database, plus context you add | Paid plans from $50 a month |
ChatGPT. The free plan offers "Unlimited text chats with GPT-6" and "Limited messages with uploads", and data analysis on uploaded files is marked limited. Good for a one-off query when you paste the schema yourself; it can't see your database.
Claude. The free plan is "Free for everyone", with "Limited usage every 5 hours and every week", and it can "Search the web, create files, and run code". Same rule as ChatGPT: in a plain chat it knows your tables only if you paste them in, though Claude can also "Connect your apps and tools", a database among them. This is the generator we tested.
Gemini in BigQuery. For BigQuery users, Google says "Core features around building data driven experiences are available to all editions at no additional cost", and SQL code generation is on that list. Because it works inside BigQuery, it sees your tables: Google's docs say it "requires access to both your Customer Data and metadata in BigQuery for enhanced features". The queries it writes still run on your normal BigQuery bill.
Supabase AI Assistant. Built into the Supabase dashboard for Postgres projects, it writes queries "based on your schema" and can run simple ones. Supabase's launch post from December 2024 says "No data is sent to the underlying LLM, only your schema structure." The feature page labels it "Public Alpha", and the pricing page doesn't say which plans include it.
DBeaver Community. The free desktop SQL client has an AI chat that writes SQL in the editor. You bring the model: "To use AI Assistant, sign up with a provider and activate it in DBeaver." Providers include OpenAI, Anthropic, Google and GitHub Copilot, or Ollama running locally, which DBeaver says keeps prompts on your computer. It asks before sending a connection's table names the first time.
Vanna. An open-source Python library under the MIT license for building your own question-to-SQL app. Version 2.0 is an agent that runs SQL on your database through a tool, works with OpenAI, Anthropic, Ollama and other models, and takes extra context such as documentation. Self-hosting is free apart from the model you call; Vanna's paid plans start with Explorer at "$50 per month".
Some well-known generators are trials rather than free plans. AI2SQL says "Every plan starts with a 7-day free trial, $0 today", with plans from $9 a month and "Card required to start your 7-day trial." SQLAI.ai's cheapest plan is $5 a month, "7 days free, then billed $60 yearly". Text2SQL.ai calls itself free to try, but its pricing page showed only an under-construction message on 1 December 2026.
For a wider comparison, including open-source engines and BI tools with built-in natural language, see the best text-to-SQL tools for data teams and AI SQL agents that chat with your database.
How to check AI-generated SQL before you trust it
- Run it on the real database. If it fails, the error usually names the invented table or column.
- Check the filters. Look at every date range, status filter and
WHEREclause. A wrong filter returns a believable number; a syntax error at least fails loudly. - Compare one number with a figure you already know, such as last month's revenue from your finance report.
- Count rows before and after joins. A join that duplicates rows inflates every sum.
- Read its assumptions. In our test, the warning that would have caught the bad growth figure was in the note under the query.
Our 17 SQL query examples show what correct output looks like for common business questions, run on a real database, and DuckDB vs pandas covers the setup we used for checking.
Where Fastero fits
The generators above stop at the SQL: you still run it, check it and put the result somewhere your team can see. In Fastero, an AI and data platform where people and AI agents work together on a team's data, the AI chat works on a database you've connected or on CSV and Excel files you upload (up to 10 at a time, 50 MB each). It writes the SQL, runs it, and builds dashboards and reports from the result, and you can see the SQL it ran, so you can check it the way this article suggests. Colleagues sign in to see the dashboards, and viewers are free.
Because it works on the connection or file itself, there's no schema to paste, but it can still misread a question. The checks above apply to it too. The Free plan has no end date and includes $20 of AI usage to start; see pricing.

Fastero's AI chat building a dashboard from an uploaded CSV. Sample data.
FAQ
Is there a free AI SQL query generator?
Yes. The free plans of ChatGPT and Claude write SQL if you paste your schema. Gemini in BigQuery includes SQL generation at no extra cost for BigQuery users, and DBeaver Community and the open-source Vanna library are free apart from the AI model they call.
Can ChatGPT write SQL queries?
Yes, but it only knows your tables if you paste them in. In our test with Claude, which works the same way, queries written from the question alone failed five times out of five; with the schema they all ran. Paste the CREATE TABLE statement, a few sample rows and the date range the data covers.
How accurate are AI SQL generators?
It depends mostly on what they know about your data. In our test, Claude's SQL was right four times out of five with the schema and never ran without it. The wrong answer was valid SQL that compared 10 months with 12, so check the filters and dates even when a query runs.
Is it safe to paste my database schema into an AI tool?
A schema holds table and column names, not your data, and database tools such as DBeaver and Supabase say they send only that. Don't paste real customer rows into a chatbot unless your company allows it, and check the provider's data policy. A local model through Ollama keeps everything on your machine.
Can AI write SQL for a CSV or Excel file?
Yes. DuckDB queries a CSV file directly with read_csv_auto, so a generator that knows the file's columns can write SQL for it. Tools such as Fastero let you upload CSV or Excel files and ask questions, and the AI writes and runs the SQL. See analyzing Excel and CSV files with SQL.
What's the best prompt for generating SQL?
Name the database, paste the schema of every table involved, add a few sample rows and the date range, define your business terms and ask the model to list its assumptions. The template above has all six parts.
Sources
Read on 1 December 2026. The SQL in our test was written by Claude and run by us; the prompts, replies, scripts and results are kept with our research notes.
- OpenAI: ChatGPT pricing
- Anthropic: Claude pricing
- Google Cloud: Gemini for Google Cloud pricing, Gemini in BigQuery overview
- Supabase: AI Assistant, Assistant v2 launch post, pricing
- DBeaver: AI Assistant, AI and data privacy, AI in DBeaver Community
- Vanna: GitHub README, pricing
- Trials: AI2SQL pricing, SQLAI.ai pricing, Text2SQL.ai
- Tools used in the test: DuckDB, pandas
Try Fastero free: connect a database or upload a CSV, ask in plain English, and see the SQL the AI ran before you share the dashboard. No credit card required.
Fastero Dev Team