What Is Text-to-SQL?
Text-to-SQL is the AI technique of turning a question written in plain language into a SQL query. Someone asks "What were sales by region last quarter?" and a large language model works out which tables and columns to use, writes the query, runs it and returns the answer.
Text-to-SQL sits behind many of the AI data assistants on the market. The same idea applies to other query languages. Against a Power BI semantic model, the AI writes DAX instead of SQL.
How Text-to-SQL Works
- Schema linking. The AI finds the tables, columns and relationships that match the words in the question.
- Query generation. It writes a query using what it found, including filters, joins and aggregations.
- Execution. The query runs against the database or semantic model.
- Explanation. The AI turns the result into a sentence, a table or a chart, ideally with the query shown.
Why Text-to-SQL Struggles on Raw ERP Tables
ERP databases are built for transactions, not questions. JD Edwards, for example, stores general ledger detail in the account ledger table (F0911), with coded column names and dates stored as numbers. Thousands of tables, cryptic names and rules that live outside the schema make schema linking hard.
The bigger problem is what the schema doesn't say. Which order types count as sales, whether revenue is stored as a negative credit, which currency each company reports in: none of that is in the column names. A generated query can run, return a number and look right while adding up companies in different currencies or counting canceled lines. A wrong answer that looks right is worse than an error.
How to Make Text-to-SQL Reliable
- Give it governed measures. With a semantic layer, the AI picks a defined measure instead of writing the math.
- Describe everything. Business names and descriptions on tables, columns and measures.
- Narrow the scope. Expose the subject area a question needs, not the whole database.
- Add examples. Sample questions with approved queries show the AI how the business asks.
- Show the work. Display the measure, filters and date range used, so people can check the answer.
- Test with traps. Include questions that tempt a wrong shortcut, such as mixed currencies.
Text-to-SQL vs Natural Language Query
Natural language query is the broader idea of asking data questions in everyday language. Text-to-SQL is one way to deliver it, by generating SQL. Other approaches map the question to predefined measures or approved answers instead of writing a new query each time.
Frequently Asked Questions
What's the difference between text-to-SQL and a semantic layer?
Text-to-SQL writes a new query from the raw schema each time. A semantic layer defines the measures, relationships and business rules once, so an AI tool can pick a governed measure instead of writing the math. Many AI tools now combine the two, generating queries against a semantic layer.
How accurate is text-to-SQL?
It depends on what the AI has to work with. Clear, well-described data with governed measures produces far better results than raw tables with coded names and business rules that live outside the database.
Is text-to-SQL the same as natural language query?
Text-to-SQL is one way to deliver natural language query. Natural language query is the broader goal of asking data questions in everyday words.
Can text-to-SQL work on ERP data?
It can run, but raw ERP tables don't carry the business logic needed for correct answers. It works much better against a semantic model that defines the measures.
Text-to-SQL and QuickLaunch's Approach
QuickLaunch Analytics gives AI tools governed measures to choose from instead of raw tables to decode. Each Application Pack, from JD Edwards and Vista to NetSuite and OneStream, carries its system's business logic in a governed semantic model, and QuickLaunch semantic models ship with the descriptions and instructions AI tools read. With Trusted Answers, a Claude plugin from QuickLaunch, each answer shows the measure, filters and source behind it, and labels each number Verified or Derived, so people know what they can act on. See our AI page.
More plain-English definitions of data, analytics and AI terms are in the QuickLaunch Learning Center.