AI SQL Assistant: The Schema-Aware Way to Query Your Database
TableAI's AI SQL assistant reads your real schema to write SQL for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server and Redshift, using your own AI key.
Andrei Yakushau
Technical Writing
An AI SQL assistant writes useful SQL only when it knows your actual database, and a native desktop app can read that schema directly. TableAI’s AI SQL assistant knows your table names, column types, keys and relationships, so the SQL it writes uses the names and dialect of your real database. Generic AI tools guess at your schema; TableAI gives the model your real database metadata.
This guide covers how schema-aware AI SQL generation works, why generic AI tools fail at real databases, and how the assistant in TableAI, an AI SQL client for Mac, solves the problem with a privacy-first architecture that keeps your credentials on your Mac and sends AI requests only to the provider you choose.
Key Takeaways
- Generic AI tools don’t know your database schema, producing SQL that fails when you run it
- Schema-aware AI reads actual database metadata (tables, columns, keys, relationships) before it writes SQL
- You bring your own API key: requests go straight from your Mac to your AI provider, with no TableAI server in between
- Agent mode runs read-only checks on your database and returns an answer, with the SQL it used
- TableAI supports OpenAI, Anthropic, DeepSeek, Alibaba Cloud and OpenRouter
The Problem: Generic AI Doesn’t Know Your Database
Ask ChatGPT to write a SQL query and it will produce something that looks right. The table names are plausible. The joins follow a reasonable pattern. The column references are grammatically correct. And then you run it against your actual database and it fails, because ChatGPT was generating SQL from pattern recognition, not from your database’s actual schema.
This is the core problem with generic AI for SQL. These tools don’t have access to your database metadata. They don’t know that your orders table has a customer_id column that references users.id, or that your products table uses snake_case while your app layer uses camelCase, or that your price column is a BIGINT storing cents, not a DECIMAL storing dollars.
The result is AI-generated SQL that fails in three common ways:
Wrong table or column names. ChatGPT invents table names like user_accounts when your actual table is auth_users. It assumes column names it can’t possibly know.
Wrong SQL dialect. PostgreSQL, MySQL and SQL Server handle ILIKE vs LIKE, LIMIT vs TOP, and date arithmetic differently. Generic AI doesn’t consistently pick the right dialect for your database.
Missing business logic. Your database has conventions, constraints, and relationships that no AI can infer from a prompt alone. Foreign key names, soft-delete patterns, audit columns, and naming conventions are invisible to tools that can’t read your schema.
GitHub Copilot and similar code assistants have the same limitation. They complete code based on what they’ve seen in training data, not based on what your actual database contains. For a wider comparison of client capabilities, you can read our breakdown of the Best Database Client for Mac.
What “Schema-Aware” Actually Means
A schema-aware AI SQL assistant receives your actual database metadata as context before it writes any query. In TableAI, that metadata includes:
- Table names and schemas: Which database, which schema, which tables exist.
- Column names and types:
idis aBIGSERIAL,priceis aBIGINT,emailisTEXT. - Primary and foreign keys: Which columns are IDs, and how tables relate to each other.
- Column comments: The notes your team left on columns, which often explain what a value means.
- Row count estimates: How large each table is, from the database’s own statistics. A query against a 10-row table behaves differently than one against 10 million.
In TableAI you choose what context the chat gets. Turn on Database Schema and the assistant gets these definitions, read from your database’s system catalogs (like the PostgreSQL information_schema documentation or MySQL’s equivalent metadata). Requests also include the SQL dialect and server version.
This changes everything about the output. When the AI knows that products.price stores cents as BIGINT, it writes WHERE price > 5000 (for $50.00) instead of WHERE price > 50. When it sees that orders.customer_id is a foreign key to customers.id, it writes proper JOINs without being told.
How TableAI’s AI SQL Assistant Works
The flow is straightforward: connect your database, open the AI chat, and ask a question in plain English.
You: "Find all users who signed up in the last 30 days and have never placed an order"TableAI’s assistant receives that question alongside the context you selected. It knows which tables exist, which columns to reference, and how the relationships work. It writes SQL for your actual database structure.
What happens next depends on the chat mode. In Chat mode the AI has no database tools: it answers with SQL, and Apply to SQL Editor puts that SQL in the editor without running it. You read it, change it if needed, and run it yourself. In Agent mode the AI can run read-only queries on its own to check its work; anything that would change data or schema comes back to you as SQL to review.
Behind the scenes, the Chat mode workflow looks like this:
- You describe what you need in plain English: a question, a request for analysis, or a description of a report you want.
- TableAI adds the context you chose, such as table names, column types, keys, relationships and row estimates.
- The LLM writes SQL using that context. Because the AI knows your actual schema, the output references real table and column names.
- You review the SQL in the chat, then apply it to the SQL editor to edit or run it.
- Results appear in the data grid, TableAI’s native result grid, which stays fast on large results.
When you run the SQL, your connection’s query guardrails apply. In Safe Mode, read-only SQL runs and anything that changes data or schema asks for approval first.
The AI assistant works with the LLM provider you bring: OpenAI, Anthropic, DeepSeek, Alibaba Cloud or OpenRouter. You supply your own API key. TableAI never sits in the middle of that connection.
The Privacy Architecture: Why BYOK Matters for Database Queries
If an AI SQL tool runs its own backend, your schema passes through that vendor’s servers on the way to the model. Your database structure, table names, column names and relationship patterns then sit with one more company. Whether that matters depends on your threat model, but for teams handling customer data, PII, or proprietary business logic, it’s a real exposure.
TableAI has no backend. When you connect a database and use the AI assistant, this is what does and doesn’t happen:
What doesn’t happen:
- Your database credentials are not sent anywhere: they stay in the macOS Keychain.
- Your schema, queries and results don’t pass through any TableAI server. There isn’t one.
- TableAI collects nothing in the background: no analytics, no tracking, no third-party SDKs.
- There is no TableAI account required to use AI features.
What does happen:
- Your LLM requests go directly from your Mac to your chosen provider, with the context you selected.
- Your database connection stays between your Mac and your database server.
- Query history and saved chats stay on your Mac.
This is not a privacy policy, it’s how the architecture works. There are no third-party SDKs, no analytics libraries, and no cloud relay for AI calls. Your API key goes directly to the provider you chose. TableAI is never in that loop.
For teams evaluating AI SQL tools, the BYOK (bring your own key) model is worth understanding in detail. It means you control which LLM provider is used, you can audit usage and costs through your own provider dashboard, and you don’t add another vendor to your security review. If you already use OpenAI or Anthropic (see Anthropic API documentation) for other AI features, you can use the same keys in TableAI.
Real-World Example: From Question to Answer
The AI Database Agent takes the schema-aware assistant further. In Agent mode, the AI searches your schema, runs read-only queries, checks the results, and returns an answer instead of another query to run.
Consider a practical scenario. A product manager at a small SaaS company needs to answer a recurring question: “Which accounts activated the new feature in the first week, then stopped using it after day 3?” Previously, this required filing a SQL ticket with the engineering team and waiting a day or two.
With TableAI’s Agent mode, the workflow looks like this:
You: "Find all accounts that created a workspace in the last 30 days, used the API integration at least once in their first 2 days, but made no API calls in the following 5 days. Group by account creation date and show signup source."The agent searches the schema, identifies the relevant tables (accounts, workspaces, api_events), writes read-only queries, runs them, checks the results, and returns an analysis. You see each step while it works, with the SQL it ran. Query results go to your AI provider, so by default TableAI asks before the first automatic read-only preview.
This is the practical value of an AI that knows your schema and can check its own work against the data. You ask a question and get an answer, with the evidence behind it.
Why Desktop Matters for AI SQL Tools
A cloud-based AI SQL tool has to reach your database or schema from its own servers to help you. That access has to live somewhere, and “somewhere” is the vendor’s infrastructure.
Desktop tools don’t have this problem. TableAI runs on your Mac, connects directly to your database, and the AI calls go directly to your LLM provider. There’s no relay, no proxy, and no server-side component that holds your schema.
This has practical implications beyond privacy:
Latency. The query runs against your database server directly. There’s no additional hop through a cloud relay.
Access to private databases. If your database is on a private network, behind a VPN, or only reachable through an SSH tunnel, a cloud tool can’t reach it. TableAI runs where you run.
No account required. TableAI doesn’t require a separate account or subscription for AI features. You bring your own LLM API key and you’re running.
Native performance. TableAI is a native macOS app, fast to launch, fast to scroll, fast to query. There’s no Electron overhead and no browser tab.
How a Schema-Aware Assistant Differs from Pasting into a Chatbot
| Step | TableAI | A general chatbot |
|---|---|---|
| Schema context | Read from your database, in the context you choose | Whatever you paste into the prompt |
| SQL dialect | Sent with each request | You have to say it |
| Running the SQL | Apply to the SQL editor, or Agent mode runs read-only checks | Copy, switch apps, paste |
| Where requests go | From your Mac straight to your AI provider | To the chatbot’s service |
| Databases | PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Amazon Redshift | Any, if you describe the schema |
| Database health report | AI Database Analysis in Admin › AI Analysis | No |
TableAI combines schema-aware AI, your own AI key, no relay server, a native Mac app and database admin tools in one client.
Getting Started with TableAI’s AI SQL Assistant
Download TableAI from the Mac App Store. Connect your database: PostgreSQL, MySQL, MariaDB, SQLite, SQL Server or Amazon Redshift. Add your own API key in Settings › Intelligence (OpenAI, Anthropic, DeepSeek, Alibaba Cloud or OpenRouter). Open the AI chat and ask your first question.
No account required. No separate AI pricing: your provider bills your AI usage to your own account. TableAI is free for one saved connection, with every feature, AI included. Paid plans add unlimited connections; see pricing.
If you’re currently using a generic AI tool for SQL assistance, the difference becomes clear within the first query. Ask TableAI to generate a query for your actual database and compare the result to what you’d get from pasting the same prompt into ChatGPT. The schema-aware difference shows up in the column names, the join structure, and the dialect accuracy.
TableAI is a native macOS database client for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server and Amazon Redshift. It combines a fast native data grid with AI features: a schema-aware SQL assistant, a database agent that runs read-only checks, and AI Database Analysis reports. Your database credentials stay on your Mac. Your API key goes directly to your chosen LLM provider. Learn more at tableai.org.
Key Takeaways
- Generic AI tools generate SQL from pattern matching: they don’t know your actual database schema, which means wrong table names, wrong column types, and wrong SQL dialect.
- A schema-aware AI SQL assistant reads your actual database metadata (tables, columns, types, keys, relationships) and uses that context to write queries for your database.
- With your own API key, requests go from your Mac directly to your chosen provider. Your credentials stay in the Keychain, and no TableAI server sees your schema.
- Agent mode extends the SQL assistant beyond single-query generation: it runs read-only checks and returns finished answers, and it hands you any change as SQL to review.
- TableAI supports OpenAI, Anthropic, DeepSeek, Alibaba Cloud and OpenRouter. You bring your own key, with no lock-in to a proprietary AI backend.
FAQ
How does TableAI’s AI assistant know my database schema?
TableAI reads table names, column types, keys, relationships, column comments and estimated row counts from your database’s system catalogs. When Database Schema is turned on in the chat context, it sends these definitions with your question, along with the SQL dialect and server version.
Does TableAI store or log my database schema or queries?
Your schema and queries go only to the AI provider you set up, directly from your Mac. TableAI has no server of its own and no third-party SDKs. Its local diagnostic logs exclude SQL, schemas and query results. Query history and saved chats stay on your Mac.
Does the AI run SQL without asking?
In Chat mode, no: you get SQL to review, and Apply to SQL Editor inserts it without running it. In Agent mode, the AI runs read-only queries itself, and TableAI blocks it from running anything else. Writes, schema changes and admin SQL come back to you to review, and your connection’s query guardrails apply when you run them.
Which LLM providers does TableAI support?
OpenAI, Anthropic, DeepSeek, Alibaba Cloud and OpenRouter. You bring your own API key, and TableAI doesn’t provide or proxy AI calls.
Can I use TableAI with databases behind a firewall or VPN?
Yes. TableAI runs on your Mac and connects directly to your database, also through SSH tunnels. If you can reach the database from your machine, TableAI can connect to it, with no cloud relay.
Is there a free version?
Yes. TableAI is free for one saved connection, with every feature and no time limit. Paid plans add unlimited saved connections; the annual plan costs $12.99 to $49.99 a year, depending on your country.
More from TableAI Blog
Best DBeaver Alternatives for Mac in 2026: 5 Apps Compared
Five Mac apps that can replace DBeaver, compared by price, free version, AI, and database support, with a table of what you keep and what you give up.
SSMS for Mac: what to use instead
SQL Server Management Studio runs only on Windows, and Azure Data Studio is retired. These are the ways Mac users work with SQL Server now, and the tasks that still need Windows.
Best MySQL Clients for Mac in 2026: 8 Apps Compared
TableAI is the best MySQL client for most Mac users who want admin tools and built-in AI in a native app. Sequel Ace and MySQL Workbench are the best free picks.
