numeric (x+y,y) length and number of digits

Source: Internet
Author: User

When learning sql: There is this sentence:

Score Numeric (4,1)

, puzzled by how many, were troubled by irresponsible notes on old books

After Baidu search:

Numeric (X+y,y)

Where y is the number of decimal digits, x is the integer digits, and x+y is the total number of digits

Then: Numeric (4,1) Total number of digits is 4, where decimal 1 bits, Integer 4-1 = 3 bits


This is for numeric type data type, if the character type, binary data type, its

DataType (m)

The m in indicates length, occupies bytes, and the length of the number type is automatically specified by the SQL standard.


Microsoft TechNet's explanation is as follows: https://technet.microsoft.com/zh-cn/library/ms190476.aspx

Number of digits for precision, scale, and length   (Transact-SQL) Other versions   precision exponent words.   decimal digits refers to the number of digits after the decimal point.   For example, the precision of the number  123.45  is  5, and the scale number is  2. The default maximum precision for,numeric  and  decimal  data types in  SQL Server  is  38.   In earlier versions of  SQL Server , the default maximum precision is  28. The length of the numeric data type is the number of bytes that are used to store this number.   The length of the string or  Unicode  data type is the number of characters. The length of the  binary, varbinary , and  image  data types is the number of bytes.   For example, the,int  data type can have  10  bits, which are stored with  4  bytes, and do not accept decimal points. The precision of the int  data type is  10, the length is  4, and the number of decimal digits is  0. When two  char, varchar, binary , or  varbinary  expressions are concatenated, the length of the generated expression is the sum of two source expression lengths, or the  8,000  character, In the least of them. When two  nchar  or  nvarchar  expressions are concatenated, the length of the generated expression is the sum of two source expression lengths, or the  4,000  character, in the case of the lesser of the two. When using  union, except , or  INTERSECT  to compare two expressions of the same data type but with a different length, the resulting length is the larger of the two expressions. In addition to the  decimal  type, the precision and scale of numeric data types are fixed.   If the arithmetic operator has two expressions of the same type, the result is that data type and has the precision and scale defined for this type.   If an operator has two expressions of different numeric data types, the data type of the result is determined by the type precedence.   results have the precision and scale defined for the data type. The following table defines when the result of the operation is  decimal  type, how to calculate the precision and scale of the result.   When any of the following conditions are true, the result is  decimal: Two expressions are  decimal  types. One expression is a  decimal  type, and the other is a data type that is lower than  decimal  priority. The operand expression is represented by the expression  e1 (precision is  P1, the scale is  S1), and the expression  e2 (precision is  p2 and the scale is  S2).   The precision and scale of any expression of non- decimal  type, is the precision and scale defined for this expression data type.


numeric (x+y,y) length and number of digits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.