Guide MCP

How to Query Your Database with Natural Language in 2026

The way people interact with databases has changed. Natural language database querying is no longer experimental. Microsoft, Oracle, and Google Cloud have all shipped MCP servers for SQL, and tools like AI2SQL make it possible to ask questions in plain English and get executable queries back in seconds.

Mar 27, 2026 13 min read

The Shift: From Writing SQL to Describing What You Need

For decades, getting data out of a database meant writing SQL. You needed to know the syntax, understand your schema, remember which tables joined to which, and debug errors when something broke. That workflow is not going away entirely, but it is no longer the default for most people who need data.

In 2026, the dominant pattern is different. You describe what you want in plain English, and an AI model generates the SQL for you. The model reads your database schema, understands your table relationships, picks the right dialect, and produces a query you can review and execute.

This is not the same as asking ChatGPT to write a query. The difference is infrastructure. The new generation of natural language database tools connects directly to your database through standardized protocols, reads your actual schema, and validates the generated SQL before it runs. The result is a query that references your real tables and columns, not hallucinated ones.

Three things converged to make this practical:

  • LLMs got good enough at SQL generation. Models like Claude and GPT-4 achieve 85-95% accuracy on standard queries when given proper schema context. That is high enough for daily use with a review step.
  • MCP standardized the connection layer. The Model Context Protocol gave AI models a consistent way to connect to databases, read schemas, and execute queries. No more custom integrations for every tool.
  • Enterprise vendors shipped production-ready servers. Microsoft, Oracle, and Google Cloud all released official MCP servers for their database products in early 2026, signaling that this is not a toy anymore.

The practical impact is significant. Product managers who used to wait two days for a data team query can now answer their own questions. Analysts who spent 40% of their time writing boilerplate SQL can focus on interpretation instead. Business teams can pull their own reports without filing tickets.

The MCP Ecosystem Explosion

The Model Context Protocol changed how AI tools interact with databases. Instead of each tool building custom database connectors, MCP provides a standard interface. An AI assistant connects to an MCP server, reads the available tools (like "query this database" or "list tables"), and uses them as needed.

In Q1 2026, the MCP database ecosystem went from experimental to mainstream. Here is what happened:

Microsoft Data API Builder (DAB) MCP

Microsoft released an MCP server built on their Data API Builder. It supports SQL Server, Azure SQL, PostgreSQL, MySQL, and Cosmos DB. The server exposes REST and GraphQL endpoints that AI models can call, with built-in authentication and role-based access control. It is designed for enterprise teams already on the Microsoft stack.

Oracle SQLcl MCP

Oracle added MCP support to SQLcl, their command-line SQL tool. The MCP server exposes schema browsing, query execution, and PL/SQL support. It works with Oracle Database, Autonomous Database, and MySQL HeatWave. Oracle's implementation focuses on DBA workflows, including explain plans, performance tuning suggestions, and schema comparison tools.

Google Cloud SQL MCP

Google Cloud launched MCP servers for Cloud SQL (PostgreSQL, MySQL, SQL Server), AlloyDB, and Spanner. Their implementation includes IAM-based authentication, query cost estimation before execution, and integration with BigQuery for analytical queries. The BigQuery MCP server is particularly useful for data teams running large analytical workloads.

AI2SQL MCP

AI2SQL released an MCP server that connects to any database (PostgreSQL, MySQL, SQL Server, SQLite, Snowflake, BigQuery, Redshift, and more) and works directly inside Claude Code and other MCP-compatible clients. The focus is on simplicity: connect your database, ask questions in English, review the generated SQL, and execute. No infrastructure setup, no cloud dependency, no vendor lock-in.

The significance of this ecosystem is not just the number of options. It is that MCP created a standard. You can switch between AI assistants without rebuilding your database integration. Your schema context, access controls, and query history travel with the MCP server, not the AI client.

How Natural Language Database Querying Works

The pipeline from English to executed query follows four stages. Understanding these stages helps you get better results and troubleshoot when things go wrong.

Stage 1: Natural Language Input

You write or speak a question in plain English. The quality of your input directly affects the quality of the output. Vague questions produce vague queries. Specific questions with table names, filters, and desired output format produce precise SQL.

Good input:

"Show me total revenue per month for 2025 from the orders table, broken down by product category, excluding cancelled orders"

Weak input:

"Show me revenue data"

Stage 2: Schema Analysis

The tool reads your database schema through the MCP connection. It pulls table names, column names, data types, primary keys, foreign keys, indexes, and relationships. This context is what separates a dedicated database tool from asking a generic chatbot. With schema context, the model knows that your revenue data lives in orders.total_amount, not in a guessed column name like revenue or sales_total.

Stage 3: SQL Generation

The LLM takes your natural language input plus the schema context and generates a SQL query. It selects the right dialect (PostgreSQL syntax vs MySQL syntax vs SQL Server syntax), uses your actual table and column names, and constructs appropriate JOINs based on your foreign key relationships.

For example, the input "Show me the top 5 customers by total spending this year" becomes:

SELECT
    c.customer_name,
    c.email,
    SUM(o.total_amount) AS total_spending
FROM customers c
JOIN orders o ON c.id = o.customer_id
WHERE o.order_date >= '2026-01-01'
  AND o.status != 'cancelled'
GROUP BY c.customer_name, c.email
ORDER BY total_spending DESC
LIMIT 5;

Stage 4: Validation and Execution

Before the query runs, the tool validates it against your schema. Does every referenced table exist? Do the column names match? Are the JOIN conditions valid? Is the syntax correct for your database dialect? After validation, you review the query and approve execution. Most MCP servers require explicit user approval before running any query, which is a critical safety feature.

The result comes back as structured data that you can read directly in your AI assistant, export to CSV, or pipe into another tool.

Setup Options Compared

Each MCP database server has different strengths. Here is a practical comparison to help you choose:

MCP Server Supported Databases Setup Complexity Best For Auth Model
Microsoft DAB SQL Server, Azure SQL, PostgreSQL, MySQL, Cosmos DB Medium (Azure config required) Microsoft/Azure teams Azure AD, API keys
Oracle SQLcl Oracle DB, Autonomous DB, MySQL HeatWave Medium (Java + SQLcl install) Oracle shops, DBAs Oracle Wallet, username/password
Google Cloud SQL Cloud SQL, AlloyDB, Spanner, BigQuery Medium (GCP project setup) GCP teams, BigQuery users IAM, service accounts
AI2SQL MCP PostgreSQL, MySQL, SQL Server, SQLite, Snowflake, BigQuery, Redshift, Oracle Low (npm install + connection string) Any team, any database Connection string

The vendor-specific servers (Microsoft, Oracle, Google) are the right choice if you are already deep in that ecosystem and want tight integration with their identity and access management systems. AI2SQL MCP is the right choice if you want a database-agnostic solution that works with any engine and sets up in minutes.

Step by Step: Setting Up AI2SQL MCP in Claude Code

Here is how to set up natural language database querying with AI2SQL MCP in Claude Code. The entire process takes under five minutes.

Step 1: Install the AI2SQL MCP Server

Open your terminal and install the AI2SQL MCP package:

npm install -g @ai2sql/mcp-server

Step 2: Configure Your Database Connection

Add the AI2SQL MCP server to your Claude Code configuration. Open your MCP settings file and add:

{
  "mcpServers": {
    "ai2sql": {
      "command": "ai2sql-mcp",
      "args": ["--connection-string", "postgresql://user:pass@host:5432/mydb"]
    }
  }
}

Replace the connection string with your actual database credentials. AI2SQL MCP supports PostgreSQL, MySQL, SQL Server, SQLite, Snowflake, BigQuery, and Redshift connection strings.

Step 3: Verify the Connection

Start Claude Code and ask a simple question about your database:

"List all tables in my database"

Claude will use the AI2SQL MCP server to read your schema and return a list of tables with their columns. If this works, your connection is set up correctly.

Step 4: Start Querying

Now you can ask questions in plain English and get SQL queries generated against your actual schema:

"How many new users signed up each week for the last 3 months?"

Claude generates the SQL, shows it to you for review, and executes it after your approval:

SELECT
    DATE_TRUNC('week', created_at) AS week,
    COUNT(*) AS new_signups
FROM users
WHERE created_at >= CURRENT_DATE - INTERVAL '3 months'
GROUP BY DATE_TRUNC('week', created_at)
ORDER BY week DESC;

Step 5: Iterate and Refine

If the result is not exactly what you need, refine your question. You can say things like "also include the signup source" or "exclude test accounts where email contains @test.com" and the tool regenerates the query with your additions.

More complex questions work the same way:

"Show me monthly recurring revenue by plan tier for the last 12 months, with month-over-month growth percentage"
WITH monthly_mrr AS (
    SELECT
        DATE_TRUNC('month', s.period_start) AS month,
        p.tier,
        SUM(s.amount) AS mrr
    FROM subscriptions s
    JOIN plans p ON s.plan_id = p.id
    WHERE s.status = 'active'
      AND s.period_start >= CURRENT_DATE - INTERVAL '12 months'
    GROUP BY DATE_TRUNC('month', s.period_start), p.tier
)
SELECT
    month,
    tier,
    mrr,
    LAG(mrr) OVER (PARTITION BY tier ORDER BY month) AS prev_month_mrr,
    ROUND(
        (mrr - LAG(mrr) OVER (PARTITION BY tier ORDER BY month))
        / NULLIF(LAG(mrr) OVER (PARTITION BY tier ORDER BY month), 0) * 100,
        1
    ) AS mom_growth_pct
FROM monthly_mrr
ORDER BY month DESC, tier;

The tool handles CTEs, window functions, and multi-step calculations because it understands your schema and the SQL dialect you are using.

Limitations and When You Still Need Raw SQL

Natural language database querying is powerful, but it is not a complete replacement for SQL knowledge. Here are the situations where you still need to write or heavily edit SQL by hand:

Performance-Critical Queries

AI-generated queries are correct but not always optimized. If you are running a query that scans millions of rows or executes thousands of times per second, you need to manually tune it. This includes choosing the right indexes, restructuring subqueries as JOINs (or vice versa), using query hints, and analyzing execution plans. Natural language tools generate functional SQL, not optimal SQL.

Database Migrations and DDL

Creating tables, altering schemas, managing indexes, and writing migration scripts require precision that natural language input struggles to capture fully. You need to specify exact data types, constraints, default values, and cascade behaviors. While you can ask an AI to draft a migration, you should write the final version by hand.

Stored Procedures and Complex Business Logic

Multi-step procedures with error handling, transaction management, cursor operations, and conditional branching are difficult to express in a single natural language prompt. These are better written as traditional code with proper version control and code review.

Write Operations on Production

Never let an AI tool run INSERT, UPDATE, or DELETE statements on production data without careful review. Most MCP servers default to read-only access for good reason. If you need to modify data, generate the query with AI, review it thoroughly, test it on staging, and then execute it manually in a controlled environment.

Ambiguous or Domain-Specific Terminology

If your schema uses cryptic column names like flg_acct_sts_cd or domain-specific terms that the LLM has not seen in training data, accuracy drops. You can mitigate this by providing a data dictionary or column description file that the MCP server includes in its schema context, but some schemas are inherently harder to query with natural language.

Multi-Database Queries

If your analysis requires joining data across multiple databases (for example, joining a PostgreSQL transactional database with a BigQuery analytics warehouse), natural language tools handle each database independently. Cross-database queries still require manual orchestration or a dedicated data warehouse that combines both sources.

The practical rule is this: use natural language querying for exploration, reporting, and ad-hoc analysis. Use hand-written SQL for anything that touches production data, requires performance guarantees, or involves schema changes.

Frequently Asked Questions

Can I query any database with natural language?

Most natural language query tools support major SQL databases including PostgreSQL, MySQL, SQL Server, SQLite, Oracle, Snowflake, BigQuery, and Redshift. MCP-based tools like AI2SQL MCP work with any database that has a compatible driver. The key requirement is that the tool can read your schema to generate accurate queries.

What is an MCP server for databases?

MCP (Model Context Protocol) is a standard that lets AI models connect to external tools and data sources. A database MCP server exposes your database schema and query execution capabilities to AI assistants like Claude, allowing them to generate and run SQL queries based on your natural language requests. Microsoft, Oracle, Google Cloud, and AI2SQL all offer database MCP servers.

Is it safe to let AI run queries on my production database?

Most MCP database servers default to read-only access, which prevents any accidental data modification. For production use, always configure your connection with a read-only database user, review generated queries before execution, and use tools that require explicit approval before running each query. Never grant write access to AI tools on production data without proper safeguards.

How accurate is natural language to SQL conversion in 2026?

Schema-aware tools achieve 85-95% accuracy on standard queries including SELECTs, JOINs, GROUP BY, and WHERE clauses. Accuracy improves significantly when the tool has access to your actual database schema rather than guessing table names. Complex analytical queries with nested subqueries or window functions may require one or two rounds of refinement.

What is the difference between AI2SQL and using ChatGPT for SQL?

AI2SQL connects directly to your database schema and generates SQL that matches your exact tables, columns, and relationships. ChatGPT generates SQL from general knowledge without seeing your schema, which leads to hallucinated table names and incorrect column references. AI2SQL also validates queries before execution and supports running them directly against your database through its MCP server.

Query Your Database in Plain English

Stop writing SQL by hand. Connect your database and ask questions in natural language. AI2SQL generates accurate, schema-aware queries in seconds.

Try AI2SQL Free

No credit card required