SQL Server Interview Question #26
What do precision and scale mean in DECIMAL?
Data Types, Keys & Constraints Junior Beginner
Detailed Explanation
Precision is the total maximum number of decimal digits that can be stored. Scale is the maximum number of digits stored to the right of the decimal point.
For DECIMAL(18,2), precision is 18 and scale is 2. Therefore, up to 16 digits can appear before the decimal point and 2 digits after it.
Choosing appropriate precision and scale is particularly important for prices, financial balances, percentages, measurements, and calculated values.
Code Example
DECLARE @Amount DECIMAL(18,2) = 123456.78;
SELECT @Amount;