Back to Blog
SQL: The Original AI Agent
Technology

SQL: The Original AI Agent

Max Li
Max Li
March 20, 2026

For the last few years, the tech world has been captivated by AI agents. Autonomous systems that can interpret intent, plan steps, and execute actions on our behalf feel revolutionary. We describe them as goal-driven, declarative, and intelligent.

But database experts have been living in this world for decades.

Long before modern AI agents were orchestrating APIs and reasoning over tools, SQL (Structured Query Language) was quietly pioneering the same idea: you tell the system what you want, and it figures out how to get it.

In that sense, SQL is the original AI agent.


The Power of Declarative Thinking

Most traditional programming languages are imperative. You describe how to do something:

  1. Open the data file
  2. Loop through rows
  3. Filter the rows
  4. Aggregate results
  5. Sort the output

You micromanage the process.

SQL is different.

With SQL, you simply say:

sql
SELECT AVG(gpa)
FROM students
WHERE enrollment_date > '2020-01-01'

You didn't specify:

  • Which index to use
  • Whether to scan sequentially or via B-tree
  • How to parallelize
  • How to reorder joins
  • Whether to use hash aggregation or sort aggregation

You described the goal, not the procedure.

That's declarative programming. And that's exactly the philosophy behind modern AI agents.


The Query Optimizer: The Hidden Intelligence

Behind every SQL query lies one of the most sophisticated pieces of software engineering ever built: the query optimizer.

Take databases like:

  • PostgreSQL
  • Oracle Database
  • Microsoft SQL Server

Each contains a cost-based optimizer that:

  • Analyzes table statistics
  • Estimates cardinalities
  • Rewrites queries
  • Chooses join orders
  • Selects execution strategies

This is not trivial rule execution. It's search, estimation, cost modeling, and plan selection under uncertainty.

Sound familiar? Let us check agents.

Modern AI agents:

  • Interpret a task
  • Break it into substeps
  • Choose tools
  • Optimize execution paths
  • Adjust based on context

SQL engines have been doing structured optimization since the 1970s.


You State Intent. The System Plans.

Let's compare.

AI Agent Prompt:

🤖 AI Agent Prompt

"Find the top 10 customers by revenue in the last quarter and email the report."

The agent:

  • Interprets "top 10"
  • Determines relevant data sources
  • Queries them
  • Aggregates revenue
  • Sorts results
  • Formats output
  • Sends email

SQL Query:

sql
SELECT customer_id, SUM(amount) AS total_revenue
FROM orders
WHERE order_date >= '2025-10-01'
GROUP BY customer_id
ORDER BY total_revenue DESC
LIMIT 10;

SQL:

  • Determines index usage
  • Selects join strategy
  • Applies aggregation algorithm
  • Sorts efficiently
  • Returns results

You provide intent.
The engine performs planning and execution.

That's agent behavior.


Abstraction Is Intelligence

We often associate "intelligence" with natural language or machine learning. But intelligence in computing is also about abstraction.

SQL abstracts:

  • Physical storage
  • Execution order
  • Parallelism
  • Access paths
  • Optimization strategy

You operate at the level of relational algebra, not disk blocks or CPU instructions.

In AI terms, SQL gives you:

  • Goal specification
  • Automated planning
  • Optimized execution
  • Tool orchestration (indexes, memory, parallel workers)

It's just that the domain is structured data rather than unstructured language.


Cost-Based Reasoning Before It Was Cool

Modern AI agents often rely on:

  • Heuristic reasoning
  • Search over possible action sequences
  • Evaluating outcomes
  • Selecting the lowest-cost plan

That's exactly what a cost-based optimizer does.

When you submit a query involving five joins, the optimizer may explore dozens—or hundreds—of possible join orders. It estimates the cost of each and selects the most efficient one.

This is automated reasoning under constraints.

Decades before we called it "AI orchestration," database systems were already solving complex search and optimization problems at massive scale.


Deterministic vs Probabilistic Intelligence

Of course, SQL engines differ from modern AI systems in one important way:

  • SQL is deterministic and rule-based.
  • AI agents are probabilistic and language-driven.

But the architectural pattern is strikingly similar:

SQL Engine AI Agent
Declarative queryNatural language prompt
Query plannerTask planner
Cost modelHeuristic evaluation
Execution planAction sequence
Database operatorsExternal tools

Different inputs. Same philosophy.


Why This Matters

When people talk about AI agents as something entirely new, they often overlook the decades of research in databases, and optimization theory.

Database researchers have been solving:

  • Query rewriting
  • Plan optimization
  • Resource scheduling
  • Parallel execution
  • Constraint solving

Since long before "AI agents" became a buzzword.

In many ways, modern AI systems are rediscovering principles that database systems mastered years ago.


A Lesson From SQL

SQL teaches us a profound design principle:

The more declarative the interface, the more powerful the system behind it must be.

If you want intelligent systems:

  • Let users specify intent
  • Hide execution complexity
  • Build powerful planners underneath

That's not just an AI idea.

That's a database idea.


Final Thought

So the next time someone marvels at AI agents that "figure out how to get things done," remember:

Database systems have been doing this quietly and reliably for decades.

SQL may not speak natural language.
It may not generate poetry.
It may not chat.

But when it comes to declarative intent and automated planning, SQL was there first. Programming languages come and go, but SQL stays with us, almost forever. Ever remember NoSQL? It does NOT stand for "Not SQL". It is for "Not Only SQL". A very smart abbreviation. True, modern database systems need to consider unstructured data, but structured data has a lot of properties that we should not throw them away.

Ladies and gentlemen, pay attention to database experts.

The original AI agent has been sitting in your data center all along.

Max Li

Max Li

Founder, Grassrootech

max@grassrootech.com

Max is dedicated to bridging the gap between advanced research and practical industry application. Drawing on his experience at IBM Research and Union University, he leads the development of AI solutions that drive meaningful progress.