SQRT() in SQL
Returns the square root of a non-negative number. The square root is the value that, when multiplied by itself, gives the number.
Syntax
Return type
SQRT() Function Example
What is SQRT() in SQL?
The SQRT()
function in SQL returns the square root of a given non-negative number. The square root of a number is the value that, when multiplied by itself, results in the original number. This function is commonly used in mathematical computations, statistical analysis, financial modeling, and geometric calculations. It is supported in SQL Server, MySQL, PostgreSQL, and Oracle. Since SQRT()
only works with non-negative numbers, passing a negative value may result in an error or NULL, depending on the database system.
Parameters:
number: The non-negative number to calculate the square root of
Example Use Cases:
-- Calculate distance in 2D plane
-- Find standard deviation
-- Calculate room diagonal
Notes:
Behavior: Returns NULL or error for negative inputs (DBMS-specific)
Performance Considerations: More computationally intensive than basic arithmetic
Version Info: Core mathematical function available in all major DBMS
Deprecated/Recommended Alternatives: None
Error Handling:
Error: Returns NULL if input is NULL
Recommendation: Use NULLIF or CASE to handle negative inputs
Supported Databases:
DBMS
Function / Syntax
Example
Behavior with NULL
MySQL
SQRT(X)
SQRT(16)
Returns NULL
PostgreSQL
SQRT(number)
SQRT(16)
Returns NULL
SQL Server
SQRT(float_expression)
SQRT(16)
Returns NULL
SQLite
SQRT(X)
SQRT(16)
Returns NULL
BigQuery
SQRT(X)
SQRT(16)
Returns NULL
Snowflake
SQRT(number)
SQRT(16)
Returns NULL
Athena
SQRT(number)
SQRT(16)
Returns NULL