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

  1. Open Deep Data Agent from the Hub
  2. Look for the mode selector at the top of the chat
  3. Click SQL to enable SQL Mode

Connecting a Database

Before querying, connect a datasource:

  1. Click the Settings icon
  2. Select Datasources
  3. Add your database connection
  4. Test and save

See Connecting Datasources for detailed instructions.

Your First Query

Once connected, try a simple prompt:

Show me all tables in the database

Or jump straight to analysis:

How many customers do we have?

Natural Language Queries

Simple Questions

Show me the top 10 orders by value
How many products are in each category?
What was our total revenue last month?

Filtering

Show me customers from California who ordered in 2024
Find all products with price over $100 that are in stock
List orders that haven't been shipped yet

Aggregations

What's the average order value by region?
Show me monthly revenue for the past year
Count orders grouped by status and priority

Joins

Show me customer names with their order totals
List products with their category names and supplier info
Find employees and their department managers

Complex Analysis

What's the month-over-month growth rate for each product category?
Find customers who ordered more than average
Show me the running total of sales by day

Schema 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 table
What 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 ID
Revenue is stored in the "amt" column

Query 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 region

Returns a table AND a bar chart.

Requesting Specific Charts

Show me monthly trends as a line chart
Create a pie chart of orders by status
Make a bar chart comparing this year vs last year

Working with Results

Following Up

Reference previous results in follow-up questions:

Now filter that to just California
Add the customer email to those results
Show me the details for the top result

Exporting

Export these results as CSV
Save this to Excel
Create a downloadable report

Saving Queries

Save this query for later
Create a view for this analysis

Multi-Database Support

Switching Datasources

If you have multiple databases connected:

Switch to the analytics database
Query the production datasource

Cross-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 works
Why 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 data

Be Specific About Time

Sales last month          → Which month? Be explicit
Sales in December 2024    → Clear and unambiguous

Clarify Ambiguity

If column names are unclear:

By "value" I mean the order_total column
"Region" is stored in the territory column

Handle Large Results

Show me a sample of 100 rows
Just show the count, not all rows
Limit to top 20 results

Troubleshooting

“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