Home » AI Databases » Schema Understanding

How the AI SQL Assistant Understands Your Database Schema

When you connect your MySQL or PostgreSQL database, the AI SQL assistant automatically reads your entire schema, including table names, column types, primary keys, foreign keys, indexes, and constraints. This schema map is what allows the AI to write accurate SQL queries when you ask questions in plain English, because it knows exactly what data exists and how tables relate to each other.

What the AI Reads From Your Schema

The schema scan collects several categories of information that the AI uses when generating queries:

How the AI Uses Schema Information

Matching Questions to Tables

When you ask "show me recent orders," the AI looks through your table names for something matching "orders." If you have tables called orders, order_items, and order_history, it picks the most relevant one based on your question. If ambiguous, it may ask for clarification or make its best guess based on the column structure.

Building JOIN Queries

Foreign keys are critical for multi-table queries. When you ask "show me customer names with their order totals," the AI sees the foreign key from orders to customers and writes the correct JOIN clause automatically. Without foreign keys defined in your schema, the AI can still infer relationships from column naming conventions (like customer_id matching customers.id), but explicit foreign keys are more reliable.

Choosing the Right Functions

Data types determine which SQL functions the AI applies. It uses date functions on DATE columns, string functions on VARCHAR columns, and aggregate functions (SUM, AVG, COUNT) on numeric columns. It will not try to calculate an average on a text column or apply string matching to an integer.

Handling Database-Specific Syntax

The AI adjusts its SQL syntax based on whether you are connected to MySQL or PostgreSQL. MySQL uses backtick quoting and functions like DATE_FORMAT and IFNULL. PostgreSQL uses double-quote identifiers and functions like TO_CHAR and COALESCE. The schema tells the AI which dialect to use.

Improving Schema Understanding

The more descriptive your table and column names are, the better the AI performs. A column named cust_ltv is harder for the AI to interpret than customer_lifetime_value. Similarly, a table called tbl_01 gives the AI no context, while support_tickets is immediately understandable.

If your database uses abbreviated or cryptic names (which is common in legacy systems), you can add context by telling the AI about your naming conventions. For example, "in my database, 'cust' means customer and 'ltv' means lifetime value." The AI remembers this context within the conversation.

Refreshing the Schema

The schema is scanned when you first connect your database and is cached for fast access. If you add new tables, modify columns, or change relationships, you can refresh the schema from the app settings. The refresh reads the updated structure and makes it available to the AI immediately.

Large databases: The AI handles databases with hundreds of tables. For very large schemas, the AI focuses on the tables most relevant to your question rather than including every table in its context. If a query misses a table you expect, mention it by name and the AI will include it.

Schema and Security

The schema information is used only for query generation within your account. It is not shared with other users, stored outside your session, or used for any purpose other than helping you query your own data. The AI sees only the tables and columns that your database user has permission to access, so limiting the user's permissions also limits what the AI can see. For more on this topic, see How to Secure Your Database Connection.

Connect your database and let AI understand your schema automatically. Start querying in minutes.

Get Started Free