SQL Server SQRT() Function

The SQRT() function in SQL Server calculates the square root of a number. The square root of a number is a value that, when multiplied by itself, equals the original number.



SQRT(): Definition and Usage

The SQRT() function is a fundamental mathematical function used in various calculations, particularly in areas like geometry, statistics, or any other domain where square roots are required. The input must be a non-negative number (zero or a positive number); otherwise, an error will occur.

Syntax

Syntax

SQRT(number)
      

Parameter Values

Parameter Description
number The number for which you want to find the square root. This is required and must be a non-negative number (zero or positive).

Examples

Calculating the Square Root of a Perfect Square

This example calculates the square root of 64 (which is 8 because 8 * 8 = 64).

Syntax

SELECT SQRT(64);
      
Output

8.000000
      

Calculating the Square Root of a Non-Perfect Square

This example calculates the square root of 13, which is an irrational number (a number that cannot be expressed as a simple fraction).

Syntax

SELECT SQRT(13);
      
Output

3.60555127546399
      

**Note:** The output values are approximate due to the nature of floating-point arithmetic. The exact values might vary slightly depending on your SQL Server version. If you provide a negative number as input, you'll get an error.