Text to SQL Feature
This article introduces how to use the Text to SQL feature in the MaiAgent system to help you easily query database information using everyday conversation
What is Text to SQL?
Text to SQL (also known as Text2SQL) is an intelligent tool that automatically converts natural language questions (everyday human language) into SQL database query statements. Simply put, it enables AI assistants to "understand human language" and directly operate databases.
Imagine you're a convenience store owner:
Traditional approach:
You: "Help me check how many bottles of cola were sold yesterday"
Employee: "Boss, you need to teach me how to use the POS system to query..."
You: "Click here, select there, enter conditions..."
Requires hands-on teaching, which is time-consuming.
With Text2SQL:
You: "Help me check how many bottles of cola were sold yesterday"
AI Employee: "Sure!" 💫 (automatically generates query method and calls database) → "87 bottles of cola were sold yesterday" ✅
Core Functions of Text to SQL
Natural language question → AI understanding and analysis → SQL query statement → Execute query → Return resultsWhen you ask the AI assistant "Find yesterday's best-selling beverage," the AI assistant first analyzes your question, understands you're looking for a "beverage" that was the "best-selling" "yesterday," then generates SQL syntax to query the database, and finally tells you the result: "Coca-Cola."
What Text to SQL Can Help AI Accomplish
Specific Application Scenarios
🏥 Medical Clinic
🏫 School Management
🏪 Retail Chain Store
Advantages of Text to SQL
⚡ Efficiency Improvement
Traditional approach: Requires SQL expert to write queries → 30 minutes
Text2SQL: Natural language questions → 3 seconds
🎯 Lower Barrier to Entry
No need to learn complex SQL syntax
No need to memorize database structure
Anyone can query data
📱 Real-time Interaction
Get answers immediately after asking
Support for follow-up questions
Dynamic adjustment of query conditions
How to Use Text to SQL Feature in MaiAgent
1. Enter AI Assistant Settings
Select the AI assistant you want to configure
Switch to the response mode settings page


2. Switch AI Assistant's Response Mode to Agent Mode
You must switch to Agent mode, otherwise the AI assistant cannot use the Text to SQL feature
For detailed introduction of each response mode, please refer to: Create AI Assistant

3. Enter Enterprise Database URL
Use the dropdown menu to select the database service used within the enterprise
Enter the database service URL used by the enterprise to allow the MaiAgent system to connect and operate within the database


Please ensure the URL format is correct and includes necessary connection information, such as: host name, port, database name, username, and password.
MaiAgent
Microsoft SQL Server(MSSSQL)
Connect to an existing MSSQL database by pasting the MSSQL database connection string
📍Please note: Ensure the database URL is accessible by MaiAgent service

MySQL
Connect to an existing MySQL database by pasting the MySQL database connection string
📍Please note: Ensure the database URL is accessible by MaiAgent service

Oracle
Connect to an existing Oracle database by pasting the Oracle database connection string
📍Please note: Ensure the database URL is accessible by MaiAgent service

PostgreSQL
Connect to an existing PostgreSQL database by pasting the PostgreSQL database connection string
📍Please note: Ensure the database URL is accessible by MaiAgent service

4. Click Save to Preserve Settings

This way, the AI assistant can help you quickly query your inventory, employee information, etc., and compile well-organized reports and trends for you.
Common Troubleshooting
Connection failure: Check database URL format and network connectivity
Query error: Confirm table names and column names are correct
Insufficient permissions: Check database user permission settings
Slow response: Check query complexity, consider adding indexes
Text2SQL turns AI assistants into database experts, enabling anyone to use natural language to quickly gain business insights, dramatically improving the efficiency of data-driven decision-making!
Last updated
Was this helpful?
