Press "Enter" to skip to content

Posts published in April 2026

How to call Ollama AI models from SQL Server 2025 in parallel with hint

Michal 0

If you have already installed Ollama server, for example based on this article Setting Up Ollama for SQL Server 2025: A Guide - John Deardurff, then you need to register the model on SQL Server.

Example:

CREATE EXTERNAL MODEL OllamaAI
WITH (
LOCATION = 'https://localollama/v1/embeddings',
API_FORMAT = 'OpenAI',
MODEL_TYPE = EMBEDDINGS,
MODEL = 'bge-m3'
);

Now you can start generating vector embeddings directly from SQL Server.
This allows you to convert text into vector form and later perform vector similarity comparisons.
The following example inserts embeddings for all missing rows from an existing table, using parallel execution via a query hint:

Create table dbo.SampleTable
(ProductDescriptionId int, Embedding vector(768))

Insert into dbo.SampleTable
(ProductDescriptionId, Embedding)
SELECT ProductDescriptionID,
AI_GENERATE_EMBEDDINGS(Description USE MODEL OllamaAI_2)
FROM [Production].[ProductDescription] A
WHERE
NOT EXISTS(SELECT 1 FROM dbo.SampleTable B WHERE
B.ProductDescriptionId=A.ProductDescriptionID)
OPTION (USE HINT('ENABLE_PARALLEL_PLAN_PREFERENCE'))

Enforce different SQL version by query hint

Michal 0
OPTION (USE HINT ('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_130'));--2016

OPTION (USE HINT ('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_140'));--2017

OPTION (USE HINT ('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_150'));--2019

OPTION (USE HINT ('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_160'));--2022

OPTION (USE HINT ('FORCE_LEGACY_CARDINALITY_ESTIMATION'));--Forces the query optimizer to use Cardinality Estimation model of SQL Server 2012 and earlier versions. Equivalent to trace flag 9481 or Database Scoped Configuration setting LEGACY_CARDINALITY_ESTIMATION=ON.

OPTION (USE HINT ('ENABLE_QUERY_OPTIMIZER_HOTFIXES'));--Enables query optimizer hotfixes (changes released in SQL Server Cumulative Updates and Service Packs). Equivalent to trace flag 4199 or Database Scoped Configuration setting QUERY_OPTIMIZER_HOTFIXES=ON.

Get closer to Standard in Developer Edition by query hints or database settings in SQL 2019

Michal 0

You may know, this issue has already been resolved by new SQL SERVER 2025 Standard Developer Edition.
However in case of 2019 version you can use those hints in query for the simulation:

option (use hint ('disable_batch_mode_adaptive_joins'),
use hint ('disable_batch_mode_memory_grant_feedback'),
use hint ('disable_interleaved_execution_tvf'),
use hint ('disable_deferred_compilation_tv'),
use hint ('disable_tsql_scalar_udf_inlining'))

or database scope settings:

ALTER DATABASE SCOPED CONFIGURATION SET BATCH_MODE_ON_ROWSTORE = OFF;
ALTER DATABASE SCOPED CONFIGURATION SET ROW_MODE_MEMORY_GRANT_FEEDBACK = OFF;
ALTER DATABASE SCOPED CONFIGURATION SET BATCH_MODE_MEMORY_GRANT_FEEDBACK = OFF;
ALTER DATABASE SCOPED CONFIGURATION SET CE_FEEDBACK = OFF;
ALTER DATABASE SCOPED CONFIGURATION SET DOP_FEEDBACK = OFF;
ALTER DATABASE SCOPED CONFIGURATION SET AUTOMATIC_TUNING = OFF;
ALTER DATABASE SCOPED CONFIGURATION SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = OFF);
ALTER DATABASE SCOPED CONFIGURATION SET ACCELERATED_PLAN_FORCING = OFF;

All this was consulted a partially code was provided by Microsoft Copilot, don't hesitate to ask for further details.

Intelligent Query Processing - SQL Server | Microsoft Learn