| title | VECTOR_NORM (Transact-SQL) | ||
|---|---|---|---|
| description | VECTOR_NORM takes a vector as an input and returns the norm of the vector (which is a measure of its length or magnitude) in a given norm type. | ||
| author | WilliamDAssafMSFT | ||
| ms.author | wiassaf | ||
| ms.reviewer | damauri, pookam, randolphwest | ||
| ms.date | 11/18/2025 | ||
| ms.service | sql | ||
| ms.subservice | t-sql | ||
| ms.topic | reference | ||
| ms.collection |
|
||
| ms.update-cycle | 180-days | ||
| ms.custom |
|
||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
||
| monikerRange | =sql-server-ver17 || =sql-server-linux-ver17 || =azuresqldb-current || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDE sqlserver2025-asdb-asmi-fabricsqldb]
Use VECTOR_NORM to take a vector as an input and return the norm of the vector (which is a measure of its length or magnitude) in a given norm type.
For example, if you want to calculate the Euclidean norm (which is the most common norm type), you can use:
SELECT VECTOR_NORM ( vector, 'norm2' )
FROM ...Note
VECTOR_NORM is available in Azure SQL Managed Instance with the SQL Server 2025 or Always-up-to-date update policy.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
VECTOR_NORM ( vector , norm_type )
An expression that evaluates to vector data type.
A string with the name of the norm type to use to calculate the norm of the given vector. The following norm types are supported:
norm1- The 1-norm, which is the sum of the absolute values of the vector components.norm2- The 2-norm, also known as the Euclidean Norm, which is the square root of the sum of the squares of the vector components.norminf- The infinity norm, which is the maximum of the absolute values of the vector components.
The function returns a float value that represents the norm of the vector using the specified norm type.
An error is returned if norm_type isn't a valid norm type and if the vector isn't of the vector data type.
The following example creates a vector with three dimensions from a string with a JSON array.
DECLARE @v AS VECTOR(3) = '[1, 2, 3]';
SELECT VECTOR_NORM(@v, 'norm2') AS norm2,
VECTOR_NORM(@v, 'norm1') AS norm1,
VECTOR_NORM(@v, 'norminf') AS norminf;The expected return values would be:
norm2 |
norm1 |
norminf |
|---|---|---|
| 3.7416573867739413 | 6.0 | 3.0 |
The following example calculates the norm of each vector in a table.
CREATE TABLE dbo.vectors
(
ID INT PRIMARY KEY,
v VECTOR(3) NOT NULL
);
INSERT INTO dbo.vectors (ID, v)
VALUES (1, '[0.1, -2, 42]'),
(2, '[2, 0.1, -42]');
SELECT ID, VECTOR_NORM(v, 'norm2') AS norm
FROM dbo.vectors;