MSAZ-301 · Lesson 1 of 12 · 22 min

AI capabilities in modern SQL engines

▶ Video coming soon A video version of this lesson is on the way.

Store staff at Harrow & Finch Home Supply answer the same questions every day. Which primer goes under a dark paint? Will this caulk work in a shower? What do I need to replace a toilet fill valve? The answers exist, scattered across 18,400 product records and 1,240 how-to guides, but finding them means knowing the right product name or the right search word. A customer who asks for something to stop a bathroom mirror fogging up does not know that the product is called an anti-fog film, and the old catalog search, which matches words, returns nothing useful.

In October 2026, Grace Oduya, the store operations director, asked the development team for a better way. Hana Sato, the developer who rebuilt the Finch Rewards loyalty app, spent two weeks, from October 26 to November 11, building a prototype called Ask Finch on a test copy of the catalog database, hf-sql-catalog-test-cus, an Azure SQL Database in Central US. The prototype lets a staff member type a question in everyday words and get back the most relevant products and guide passages, and, in a second step, a short written answer with links to the sources it used.

Hana is also preparing for exam DP-800, Developing AI-Enabled Database Solutions, which she plans to sit in June 2027. Her mentor for the AI parts of the work is Nikolai Petrenko, a data engineer who joined Harrow & Finch in September 2026. Nikolai has one question he asks about every design: who reads this data, and how fast do they need it? Elena Brandt, the senior DBA, joins whenever a design touches database resources, and Carmen Ortiz, the privacy officer, reviews anything that sends company or customer data to a model. This course follows the prototype, what Hana learned building it, and the decisions the team made before a store pilot planned for February 2027.

Why put AI in the database

For most of the history of relational databases, artificial intelligence lived somewhere else. A data scientist exported data to files, trained or called a model in Python, and wrote results back. Search over meaning, rather than exact words, needed a separate search service or a specialized vector database, with its own copy of the data, its own security model and its own synchronization job. Every copy is another place where data can be stale, another set of permissions to manage and another bill.

Modern SQL engines bring several of these pieces inside the database. SQL Server 2025, Azure SQL Database, Azure SQL Managed Instance and SQL database in Microsoft Fabric can store vectors in a native data type, compare them with built-in distance functions, search them with an approximate vector index, call an embedding model from T-SQL, split long text into chunks, and call any allowed REST endpoint, including a language model, from a stored procedure. The data stays where its security, backups, auditing and transactions already are, and a developer who knows T-SQL can build semantic search without learning a second database.

That does not mean every AI workload belongs in the database. Training models, running large batch inference over terabytes of data, or serving thousands of model calls a second are jobs for dedicated services. The database is a good home for AI features that sit close to operational data: searching products, finding similar support cases, grounding a chatbot in current inventory, or flagging records that look like known problems. Nikolai's rule of thumb is that if the answer depends on data that changes during the day and is already protected in the database, the AI feature should run next to that data.

The building blocks

The DP-800 outline groups the AI skills into three areas: designing and implementing models and embeddings, designing and implementing intelligent search, and designing and implementing retrieval-augmented generation. Each area uses a small set of engine features. The table summarizes them; later lessons cover each in detail.

The main AI features in SQL Server 2025, Azure SQL and SQL database in Fabric.
FeatureWhat it doesLesson
vector data typeStores an array of numbers, an embedding, in a column, displayed as a JSON array2
CREATE EXTERNAL MODELRegisters an embedding model endpoint, its format and its credential as a database object3, 4
AI_GENERATE_EMBEDDINGSCalls a registered model to turn text into an embedding3
AI_GENERATE_CHUNKSSplits long text into fixed-size pieces, optionally overlapping3
sp_invoke_external_rest_endpointCalls an allowed HTTPS endpoint, such as a chat model, and returns its JSON response4, 8
VECTOR_DISTANCE, VECTOR_NORMALIZE, VECTORPROPERTYExact distance between vectors, scaling to unit length, and reading a vector's properties5
CREATE VECTOR INDEX and VECTOR_SEARCHAn approximate nearest-neighbor index using DiskANN, and the function that queries it6
Full-text searchKeyword search with stemming and relevance ranking, combined with vectors in hybrid search7

Availability is not identical everywhere, and the exam expects candidates to notice. The vector data type with 32-bit elements is generally available in SQL Server 2025, Azure SQL Database, Azure SQL Managed Instance and SQL database in Fabric. On Managed Instance, the AI functions need the Always-up-to-date or SQL Server 2025 update policy, because they arrived with the SQL Server 2025 engine. Some pieces are still in preview in some products as of November 2026: vector indexes are still described as preview in Azure SQL Database and Fabric on one reference page and as generally available on another, a difference lesson 6 explains, and they are in preview in SQL Server 2025, where they also require the PREVIEW_FEATURES database scoped configuration, and the half-precision float16 vector type is a preview feature in SQL Server 2025 while generally available in the Azure products. Hana keeps a one-page availability table pinned to her monitor, and Nikolai reminds her to recheck it before the pilot, because preview features change.

A diagram of an Azure SQL database at the center. Inside it are four stacked layers: tables with a vector column, external models and credentials, vector indexes, and stored procedures. Arrows leave the database to an embedding model and a chat model in Microsoft Foundry, labeled HTTPS with managed identity. On the left, a staff app sends a question in and receives products and an answer back.
The Ask Finch prototype: data, vectors, models and procedures inside the database, with HTTPS calls out to models.

Embeddings in one paragraph

An embedding is a list of numbers that represents the meaning of a piece of text, an image or another item, produced by a model trained so that items with similar meaning get similar lists. The model Hana uses returns 1,536 numbers for any text it is given. The sentence stop the bathroom mirror steaming up and the product description anti-fog mirror film, prevents condensation share almost no words, yet their embeddings point in nearly the same direction. Comparing embeddings with a distance function finds related items even when the words differ. That is the whole idea behind semantic search, and lesson 3 explains how embeddings are made.

The DP-800 outline asks candidates to choose between full-text, semantic vector and hybrid search. The choice depends on what users type and what they need back.

Choosing a search method.
Search typeGood atWeak atHarrow & Finch example
Full-textExact product codes, brand names, rare technical termsSynonyms and descriptions in everyday wordsA contractor types PNT-114 or a brand name
Vector (semantic)Meaning, paraphrases, questions in plain languageExact codes, numbers, very short queriesSomething to stop the mirror fogging
HybridBoth, by merging the two ranked listsNeeds two indexes and a fusion stepLow-VOC paint for a nursery

Hana's first tests showed why the choice matters. Searching for PNT-114 with vectors returned paint, but not always that paint, because a product code carries no meaning a language model can use. Searching for something to keep my deck from going gray with full-text returned nothing, because no product description contains those words. Hybrid search, which runs both and merges the lists, handled both questions well, and it became the design for the pilot. Lesson 7 shows how.

Retrieval-augmented generation

Search returns records. Many users want an answer instead: a sentence or two that explains which product to buy and why. A language model can write that answer, but on its own it knows nothing about Harrow & Finch's stock, prices or guides, and it may invent plausible details. Retrieval-augmented generation, usually shortened to RAG, fixes this by retrieving relevant records first and sending them to the model with the question, with instructions to answer only from those records and to cite them. The database does the retrieval, a stored procedure builds the prompt as JSON, and sp_invoke_external_rest_endpoint sends it to the model. Lesson 8 builds this pipeline.

Worked problem

Choosing the approach for three requests

Grace's team sent Hana three requests. One: let contractors look up products by code or brand quickly. Two: let store staff ask questions in plain words and see matching products and guide sections. Three: give staff a short written answer with sources. Which approach fits each?

Show solution
  1. Request one uses exact identifiers. Full-text search, or even an ordinary index on the product code, answers it best; vectors add nothing for a code.
  2. Request two mixes plain-language questions with the occasional code or brand. Hybrid search covers both.
  3. Request three needs generated text grounded in company data. That is retrieval-augmented generation, using the hybrid search from request two as its retrieval step.
  4. All three share one database, one set of permissions and one copy of the data, which is the reason to build them in Azure SQL rather than export the catalog to a separate search service.

Answer: Full-text or an ordinary index for codes, hybrid search for plain-language questions, and RAG on top of hybrid search for written answers.

What changes for the developer

Building AI features in the database adds new objects and new kinds of dependency to an ordinary application. External models and database scoped credentials become part of the schema and must be deployed with it. Calls to models take tens or hundreds of milliseconds and can fail for reasons outside the database, such as throttling or an expired key, so procedures need timeouts, retries and error handling. Model output is not deterministic in the way a query is, so tests check for properties, such as whether the answer cites a source, rather than exact strings. And every call to a hosted model costs money, so design decisions about how often to generate embeddings or call a chat model show up on the monthly bill. Lessons 10 and 11 return to security and cost.

There is also a design question about where each step runs. Hana could generate embeddings inside the database with AI_GENERATE_EMBEDDINGS, or in an Azure Function triggered by changes, or in a batch job that writes vectors back. The DP-800 outline lists several ways to keep embeddings current, including table triggers, change tracking, Azure Functions with a SQL trigger binding, Logic Apps, change data capture, change event streaming and pipelines in Microsoft Foundry. Lesson 3 compares them. For the prototype, Hana did everything in T-SQL because it was the quickest way to learn, and she noted which steps would move elsewhere for production.

Natural language to SQL, and AI-assisted tools

A different use of AI is letting a person ask a question in words and have a model write the SQL query. It is tempting, because managers would love to ask how many paint returns Store 12 had last month without waiting for a report. It is also risky, because generated SQL can be wrong, slow or, without safeguards, harmful. Lesson 9 covers how to do it safely: a read-only role, a limited set of views, validation of the generated statement and showing the query to the user. The DP-800 outline also covers AI-assisted development tools, such as GitHub Copilot and Copilot in Fabric connected to a database through a Model Context Protocol server; those belong to the design and development skills taught in MSAZ-300, and this course mentions them only where they touch AI features in the database.

The prototype at the end of two weeks

By November 11, the Ask Finch prototype held embeddings for every product description and every guide section in the test database, used hybrid search for retrieval, and produced grounded answers for a set of 60 test questions that store staff had written. Hana scored each answer with Grace's store managers: 48 of the 60 answers were judged correct and useful, 7 were correct but missed a better product, and 5 were wrong or unhelpful. That is 80 in 100 correct and useful, good for a two-week prototype and not yet good enough for customers. The rest of this course follows what the team changed and why.

Python Example · Scoring the 60 test questions from the prototype.
results = {"correct and useful": 48, "correct, missed a better product": 7, "wrong or unhelpful": 5}
total = sum(results.values())
for label, n in results.items():
    print(f"{label:34s} {n:3d}  ({n * 100 / total:.1f} in 100)")
print("total questions:", total)
Output
correct and useful                  48  (80.0 in 100)
correct, missed a better product     7  (11.7 in 100)
wrong or unhelpful                   5  (8.3 in 100)
total questions: 60

What this code does

The program adds up how many of the 60 test questions fell into each of the three judgments and shows each group as a number out of 100. The output shows that 48 answers, 80 in every 100, were judged correct and useful, while 5 answers, about 8 in 100, were wrong. Hana used this summary as the baseline that later changes had to beat.

Nikolai's comment on the scores was the question he always asks. Store staff read these answers while a customer waits, so speed matters as much as accuracy, and a wrong answer delivered with confidence is worse than no answer. The pilot plan therefore has two targets: at least 90 in 100 answers judged correct and useful on a larger test set, and a typical response in under three seconds.

Common mistakes

  • MistakeAI features always need a separate vector database.

    InsteadSQL Server 2025, Azure SQL and SQL database in Fabric store and search vectors natively, next to the operational data.

  • MistakeVector search replaces full-text search.

    InsteadVectors are weak at exact codes and rare terms; hybrid search combines both.

  • MistakeA language model already knows a company's products.

    InsteadRAG retrieves company data and sends it with the question so the answer is grounded and cited.

  • MistakeEvery AI feature is generally available in every product.

    InsteadCheck availability: vector indexes are in preview in several products, and Managed Instance needs the right update policy.

Summary and key terms

  • SQL Server 2025, Azure SQL Database, Azure SQL Managed Instance and SQL database in Fabric support vectors, embeddings, model calls and vector search in T-SQL.
  • Keeping AI features next to operational data avoids extra copies, extra permissions and synchronization jobs.
  • An embedding is a list of numbers representing meaning; similar meanings give nearby vectors.
  • Full-text search suits exact terms, vector search suits meaning, and hybrid search combines them.
  • Retrieval-augmented generation retrieves relevant records and sends them to a model with the question so answers are grounded.
  • Availability and preview status vary by product; Managed Instance needs the Always-up-to-date or SQL Server 2025 update policy.
Embedding
A list of numbers produced by a model that represents the meaning of text or another item.
Semantic search
Search that finds items by meaning rather than by matching words.
Hybrid search
Search that runs keyword and vector searches and merges their ranked results.
Retrieval-augmented generation (RAG)
Answering with a language model after retrieving relevant data and including it in the prompt.
External model
A database object that records an AI model endpoint, its API format and its credential.
Update policy
The Managed Instance setting that decides which engine version and features an instance receives.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why did vector search struggle with the query PNT-114?

    Show answer

    A product code carries no meaning a language model can encode, so its embedding does not reliably match the right product; full-text or an ordinary index works better.

  2. Name the three AI skill areas in the DP-800 outline.

    Show answer

    Models and embeddings, intelligent search, and retrieval-augmented generation.

  3. What does RAG add to a language model's answer?

    Show answer

    Relevant company data retrieved from the database, with instructions to answer only from it and cite it.

  4. What must a Managed Instance have to use the SQL Server 2025 AI functions?

    Show answer

    The Always-up-to-date or SQL Server 2025 update policy.

  5. In the prototype test, how many answers in 100 were correct and useful?

    Show answer

    80, that is 48 of 60.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz