Text to SQL
Describe the data you want in plain English. Paste your schema so the query uses your real table and column names, then check and format it with one click.
Getting accurate SQL from plain English
- Give it the schema. Paste the output of
pg_dump --schema-only,mysqldump --no-dataor.schema. It is condensed to DBML before sending, so only names and types leave your browser, never data. - Name the time range and the grain. “Revenue per month in 2026” beats “revenue over time”.
- Say how to treat ties and missing data. “Include customers with no orders” tells the model to use a LEFT JOIN. See join types for why that matters.
- Check before you trust. Run it with
LIMIT 20, compare a total against a number you already know, and read the joins.
If you don’t have a schema yet, describe your app on the ER diagram generator and it drafts one you can paste here.
Questions
What is text to SQL?
Text to SQL turns a question in plain English, such as “top 10 customers by revenue this year”, into a SQL query. Large language models do this well when they can see your table and column names, which is why this tool lets you paste your schema.
Do I need to paste my schema?
It is optional but strongly recommended. Without it the model has to guess table and column names. With your CREATE TABLE statements (or DBML), it uses only names that exist and follows your foreign keys for joins.
Is the generated SQL safe to run?
Treat it like code from a colleague: read it first. The model is instructed not to write DROP, TRUNCATE, ALTER or unfiltered UPDATE/DELETE unless you ask, but always test on a development database and check row counts. The SQL validator can confirm the syntax.
What is sent to the AI model?
Your request, the chosen dialect and the schema in compact DBML form (column names and types only, no data). It goes through Vercel AI Gateway to OpenAI and is not stored by DiagramDB. Don’t paste secrets or real customer data.
Which databases are supported?
PostgreSQL, MySQL, SQL Server, SQLite, Oracle, BigQuery and Snowflake. The dialect controls details like LIMIT vs TOP vs FETCH FIRST, quoting, and date functions.
Can ChatGPT write SQL queries?
Yes. General chat assistants can write SQL, and this page uses an OpenAI model scoped strictly to SQL. The difference is the workflow: your schema is parsed and condensed automatically, the dialect is fixed, and the output goes straight into the formatter and validator.
Related tools
- SQL ValidatorCheck syntax for MySQL, PostgreSQL, SQL Server, SQLite and BigQuery, with the exact line and column.
- SQL FormatterBeautify SQL in 12 dialects with keyword case, indent and comma style options.
- SQL Dialect ConverterRewrite SQL from MySQL to PostgreSQL, SQL Server, SQLite and more, with every change listed.
- SQL Cheat SheetEvery everyday statement with a copyable example.