MSSQLTips.com · September 11, 2025
Natural Language Query for SQL Server
This article presents a prototype for translating natural language questions into T-SQL queries using SQL Server and a locally hosted large language model through Ollama. A stored procedure constructs a prompt for the AdventureWorks2017 database and invokes the Ollama REST API through PowerShell and xp_cmdshell to retrieve the generated SQL.
A DeepSeek Coder example illustrates how a question about customer purchases can be translated into a relational query without a cloud API. The discussion highlights the need for improved error handling, query validation and restricted execution permissions before adopting the approach in production.