नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
Applies to:
SQL Server 2025 (17.x)
Azure SQL Database
Azure SQL Managed Instance
SQL database in Microsoft Fabric
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.
Syntax
Transact-SQL syntax conventions
VECTOR_NORM ( vector , norm_type )
Arguments
vector
An expression that evaluates to vector data type.
norm_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.
Return value
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.
Examples
Example 1
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 |
Example 2
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;