What is the Difference Between Numeric and Decimal?

🆚 Go to Comparative Table 🆚

The main difference between the NUMERIC and DECIMAL data types in SQL lies in their precision and scale enforcement:

  1. NUMERIC: This data type enforces strict precision and scale. It truncates or rounds the value to the specified precision and scale, removing any additional decimal points or integers. For example, if you have the number 5.323 and define the NUMERIC data type as (3, 2), it will only store the value 5.32.
  2. DECIMAL: This data type is more relaxed in its enforcement of precision and scale. It allows the storage of values with higher precision and scale than specified, if that's easier to implement. For example, if you have the number 5.323 and define the DECIMAL data type as (3, 2), it may still store the entire value 5.323.

Please note that the difference between NUMERIC and DECIMAL may not be present in every SQL standard, and some databases, like SQL Server, consider them synonyms and treat them interchangeably. In Transact-SQL statements, a constant with a decimal point is automatically converted into a numeric data value, using the minimum precision and scale necessary.

Comparative Table: Numeric vs Decimal

The Numeric and Decimal data types in SQL are used to store fixed-precision and scale numbers. They are considered synonyms and can be used interchangeably. Both data types have the following properties:

  • Precision (p): The maximum total number of decimal digits to be stored, including both the left and right sides of the decimal point. The precision must be a value from 1 through the maximum precision of 38, with a default precision of 18.

  • Scale (s): The number of decimal digits to the right of the decimal point. The scale must be a value from 0 through the maximum scale of 38, with a default scale of 0.

In most databases, there is no significant difference between the Numeric and Decimal data types. However, in some specific cases, the NUMERIC data type might only go up to the specified number of decimals, while the DECIMAL data type could be at least that exact number, if not more.

Here is a summary table comparing the two data types:

Property Numeric Decimal
Precision (p) The maximum total number of decimal digits to be stored The maximum total number of decimal digits to be stored
Scale (s) The number of decimal digits to the right of the decimal point The number of decimal digits to the right of the decimal point
Interchangeability Can be used interchangeably with Decimal Can be used interchangeably with Numeric

In conclusion, there is no significant difference between Numeric and Decimal data types in most databases, and they can generally be used interchangeably.