Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The length and number of digits of numeric

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

When learning SQL: there is such a sentence:

Score numeric (4Jing 1)

I don't know how many people are troubled by irresponsible notes in old books.

After querying Baidu:

Numeric (xonomy, y)

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

Then: the total number of digits of numeric (4) is 4, including 1 decimal place and 3 integer digits.

This is for numeric data types, for character type, binary data type, its

Datatype (m)

The m in represents the length and occupies bytes; the length of the numeric type is automatically specified by the SQL standard.

Microsoft TECHNET is explained as follows: https://technet.microsoft.com/zh-cn/library/ms190476.aspx

Precision, decimal places, and length (Transact-SQL) other versions of precision refer to the number of digits. The number of decimal places is the number of digits after the decimal point. For example, the precision of the number 123.45 is 5 and the number of decimal places is 2. In SQL Server, the default maximum precision for numeric and decimal data types is 38. In previous versions of SQL Server, the default maximum precision was 28. The length of the numeric data type is the number of bytes used to store this number. The length of a string or Unicode data type is the number of characters. The length of binary, varbinary, and p_w_picpath data types is the number of bytes. For example, the int data type can have 10 digits, store in 4 bytes, and do not accept decimal points. The precision of the int data type is 10, the length is 4, and the decimal place is 0. When two char, varchar, binary, or varbinary expressions are concatenated, the length of the resulting expression is the sum of the two source expressions, or 8000 characters, whichever is less. When two nchar or nvarchar expressions are concatenated, the length of the resulting expression is the sum of the two source expressions, or 4000 characters, whichever is less. When you use UNION, EXCEPT, or INTERSECT to compare two expressions with the same data type but different lengths, the resulting length is the larger of the two expressions. Except for the decimal type, the precision and decimal places of the numeric data type are fixed. If the arithmetic operator has two expressions of the same type, the result is that data type with precision and decimal places defined for that type. If the operator has two expressions of different numeric data types, the data type of the result is determined by the priority of the data type. The result has the precision and decimal places defined for the data type. The following table defines how to calculate the precision and decimal places of the result when the result is of type decimal. When any of the following conditions are true, the result is decimal: both expressions are of type decimal. One expression is of type decimal, while the other is a data type that has a lower priority than decimal. The Operand expression is represented by the expression E1 (precision p1, decimal places S1) and expression e2 (precision p2, decimal places S2). The precision and decimal places of any expression that is not of type decimal is the precision and decimal places defined for this expression data type.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report