Wednesday, June 6, 2012

SQL Server - Precision and Scale for Numeric or Decimal DataType

Difference between Precision and Scale for Numeric or Decimal Datatype in SQL Server

Precision (P) - Precision signifies total number of digits which a Numeric OR
                     Decimal datatype can hold, 18 is the default precision

Scale (S) - Scale signifies number of digits to the right of Decimal (.) operator, scale varies
                from 0-n (where n - number defined by us)

Syntax - Numeric (Precision, Scale) OR Decimal (Precision, Scale)

E.g.  Numeric(38,2) : it says Numeric datatype can hold total of 38 digits
       of which 2 digits to the right of decimal (.) and remaining digits to the left of
       decimal (.)
       Decimal(14,2): it says Decimal datatype can hold total of 14 digits
       of which 2 digits to the right of decimal (.) and remaining digits to the left of
       decimal (.)      

No comments:

Post a Comment