AI SQL generation
How Data Explorer uses schema context, AI routing, SQL Steps, and typed recommendations to turn natural-language requests into usable SQL.
Current SQL generation flow
The backend extracts metadata from the active connection: tables, columns, relationships, and part of the query context. The AI is not forced to guess table and column names from thin air.
The routing mode in the UI is only one layer. The real chain also depends on any explicit model/provider selection, whether the prompt includes an image, and whether the request is detected as current-information work. For normal SQL tasks, the app prefers a safe text-capable chain.
If the task is SQL/query work, the backend tries to return clear SQL, an explanation, and recommendation cards such as `query_fix`, `index_suggestion`, `schema_suggestion`, or `chart_suggestion` so the UI can take the next step.
The AI SQL model role
Inherit the Assistant model
Best when you want to keep configuration simple and manage one main model for most workflows.
Use a dedicated SQL model
Best when you want AI SQL to use a different model for optimization, query fixing, index suggestions, or long join-heavy statements.
Routing modes
The default mode for most SQL work. The app starts from the appropriate auto chain and filters it by capability instead of always jumping straight to the most expensive lane.
Leans toward quicker iteration and cheaper lanes, but does not override an explicit provider if you already locked the model.
Useful when a task needs heavier reasoning, explanation, rewriting, or deeper optimization. It leans toward stronger lanes earlier.
Always uses the Gemini model you selected. Useful when you want the most stable output or want to avoid other providers entirely.
One easy misunderstanding: if a prompt is detected as a current-information request such as “latest”, “today”, or “current price”, the router leans toward live-search chat behavior instead of treating it as a pure SQL generation request.
SQL Steps / sequential multi-statement execution
When should you use it?
Great for setup scripts, data seeding, create-table plus insert plus index plus analyze flows, or any workflow where execution order matters.
What can you do in the dialog?
Drag up and down, use move up/down buttons, delete steps, add a new step, edit each step directly, then choose `Apply to editor` or `Run sequence`.
# A common SQL Steps script
CREATE TABLE perf_orders_200k_v1 (...);
INSERT INTO perf_orders_200k_v1 (...) SELECT ...;
CREATE INDEX idx_perf_orders_tenant_id ON perf_orders_200k_v1(tenant_id);
ANALYZE perf_orders_200k_v1;
Effective prompt patterns
# Sample prompt
List top 10 customers by spending in Q4 2025 with order count and total revenue.
# Sample prompt
Optimize this query and give me actionable index recommendations with runnable SQL if possible.
# Sample prompt
Suggest the best chart for this result set and explain which fields should be used.
Action cards & execution safety
AI can still suggest the wrong column, the wrong table, or a statement that does not match your real data. Review SQL before running it, especially for DDL, index creation, or operations that can affect performance.
Ready to explore data?
Join the community on GitHub to contribute to the smartest local database IDE.
Launch App