SQL Mode
SQL Mode lets you query databases using natural language, with automatic schema understanding and query validation.
Overview
When you select SQL Mode, you’re working with the SQL Agent—an AI assistant specialized in:
- Converting natural language to SQL
- Understanding database schemas automatically
- Validating and correcting queries
- Visualizing query results
- Explaining complex queries
Getting Started
Switching to SQL Mode
- Open Deep Data Agent from the Hub
- Look for the mode selector at the top of the chat
- Click SQL to enable SQL Mode
Connecting a Database
Before querying, connect a datasource:
- Click the Settings icon
- Select Datasources
- Add your database connection
- Test and save
See Connecting Datasources for detailed instructions.
Your First Query
Once connected, try a simple prompt:
Show me all tables in the databaseOr jump straight to analysis:
How many customers do we have?Natural Language Queries
Simple Questions
Show me the top 10 orders by valueHow many products are in each category?What was our total revenue last month?Filtering
Show me customers from California who ordered in 2024Find all products with price over $100 that are in stockList orders that haven't been shipped yetAggregations
What's the average order value by region?Show me monthly revenue for the past yearCount orders grouped by status and priorityJoins
Show me customer names with their order totalsList products with their category names and supplier infoFind employees and their department managersComplex Analysis
What's the month-over-month growth rate for each product category?Find customers who ordered more than averageShow me the running total of sales by daySchema Understanding
Automatic Discovery
When you connect a database, SQL Mode automatically:
- Discovers all tables and views
- Maps column names and types
- Identifies primary and foreign keys
- Understands relationships
Asking About Schema
What tables are available?Describe the customers tableWhat columns are in the orders table?How are customers and orders related?Schema Hints
If the agent misunderstands your data:
The "cust_id" column refers to customer IDRevenue is stored in the "amt" columnQuery Validation
Automatic Validation
Before running queries, SQL Mode:
- Checks syntax correctness
- Validates table and column names
- Ensures type compatibility
- Warns about potential issues
Correction
If a query would fail, the agent corrects it:
You: Show me customers from the "clients" table
Agent: I don't see a "clients" table, but I found "customers". Here's the query...Query Preview
For complex or potentially expensive queries, the agent shows you the SQL first:
Here's the query I'll run:
SELECT customer_name, SUM(order_total)
FROM orders
JOIN customers ON orders.customer_id = customers.id
GROUP BY customer_name
ORDER BY SUM(order_total) DESC
LIMIT 10
Should I run this?Results and Visualization
Table Results
Query results appear as formatted tables with:
- Sortable columns
- Pagination for large results
- Export options
Automatic Charts
For aggregated data, SQL Mode suggests visualizations:
Show me sales by regionReturns a table AND a bar chart.
Requesting Specific Charts
Show me monthly trends as a line chartCreate a pie chart of orders by statusMake a bar chart comparing this year vs last yearWorking with Results
Following Up
Reference previous results in follow-up questions:
Now filter that to just CaliforniaAdd the customer email to those resultsShow me the details for the top resultExporting
Export these results as CSVSave this to ExcelCreate a downloadable reportSaving Queries
Save this query for laterCreate a view for this analysisMulti-Database Support
Switching Datasources
If you have multiple databases connected:
Switch to the analytics databaseQuery the production datasourceCross-Database Questions
Which datasource has the customers table?What databases are connected?SQL Generation
Viewing SQL
Every response shows the SQL used. Click “Show SQL” to see it.
Learning SQL
Ask the agent to explain:
Explain how that query worksWhy did you use a LEFT JOIN here?What does the HAVING clause do?Custom SQL
You can provide your own SQL:
Run this query:
SELECT * FROM orders WHERE status = 'pending'Best Practices
Start Simple
Begin with basic questions to verify the agent understands your schema:
What tables are available?
How many rows in the orders table?
Show me a sample of customer dataBe Specific About Time
Sales last month → Which month? Be explicit
Sales in December 2024 → Clear and unambiguousClarify Ambiguity
If column names are unclear:
By "value" I mean the order_total column"Region" is stored in the territory columnHandle Large Results
Show me a sample of 100 rowsJust show the count, not all rowsLimit to top 20 resultsTroubleshooting
“Table not found”
- Check available tables: “What tables exist?”
- Verify the schema: “Describe the database”
- Check datasource is connected
Slow queries
- Add limits: “Show me the top 100”
- Ask for counts first: “How many rows match?”
- Request an index suggestion: “How can I make this faster?”
Wrong results
- Check the SQL: “Show me the query you ran”
- Verify understanding: “What columns are in that table?”
- Clarify your question with more detail
Connection issues
- Verify datasource is active in Settings
- Check credentials are correct
- Ensure the database is accessible from your workspace