Precision, Scale, and Length (Transact-SQL)
来源:互联网 发布:定时打铃软件 编辑:程序博客网 时间:2024/05/16 06:27
Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2.
In SQL Server, the default maximum precision of numeric anddecimal data types is 38. In earlier versions of SQL Server, the default maximum is 28.
Length for a numeric data type is the number of bytes that are used to store the number. Length for a character string or Unicode data type is the number of characters. The length forbinary,varbinary, andimage data types is the number of bytes. For example, anint data type can hold 10 digits, is stored in 4 bytes, and does not accept decimal points. Theint data type has a precision of 10, a length of 4, and a scale of 0.
When two char, varchar,binary, orvarbinary expressions are concatenated, the length of the resulting expression is the sum of the lengths of the two source expressions or 8,000 characters, whichever is less.
When two nchar or nvarchar expressions are concatenated, the length of the resulting expression is the sum of the lengths of the two source expressions or 4,000 characters, whichever is less.
When two expressions of the same data type but different lengths are compared by using UNION, EXCEPT, or INTERSECT, the resulting length is the maximum length of the two expressions.
The precision and scale of the numeric data types besides decimal are fixed. If an arithmetic operator has two expressions of the same type, the result has the same data type with the precision and scale defined for that type. If an operator has two expressions with different numeric data types, the rules of data type precedence define the data type of the result. The result has the precision and scale defined for its data type.
The following table defines how the precision and scale of the result are calculated when the result of an operation is of typedecimal. The result isdecimal when either of the following is true:
Both expressions are decimal.
One expression is decimal and the other is a data type with a lower precedence thandecimal.
The operand expressions are denoted as expression e1, with precision p1 and scale s1, and expression e2, with precision p2 and scale s2. The precision and scale for any expression that is notdecimal is the precision and scale defined for the data type of the expression.
Operation
Result precision
Result scale *
e1 + e2
max(s1, s2) + max(p1-s1, p2-s2) + 1
max(s1, s2)
e1 - e2
max(s1, s2) + max(p1-s1, p2-s2) + 1
max(s1, s2)
e1 * e2
p1 + p2 + 1
S1+S2e1 / e2
p1 - s1 + s2 + max(6, s1 + p2 + 1)
max(6, s1 + p2 + 1)
e1 { UNION | EXCEPT | INTERSECT } e2
max(s1, s2) + max(p1-s1, p2-s2)
max(s1, s2)
e1 % e2
min(p1-s1, p2 -s2) + max( s1,s2 )
max(s1, s2)
* The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, the corresponding scale is reduced to prevent the integral part of a result from being truncated.
- Precision, Scale, and Length (Transact-SQL)
- Storage of Scale and Precision
- CAST and CONVERT (Transact-SQL)
- Oracle Number precision scale
- NUMBER ( precision, scale)
- Hibernate 配置文件precision与scale
- Recall, Precision, and Average Precision
- Recall, Precision, and Average Precision
- Recall, Precision, and Average Precision
- Beginning Transact-SQL With SQL Server 2000 and 2005
- TRANSACT-SQL
- Transact SQL
- Transact-SQL
- Transact-sql
- Using UNION, EXCEPT and INTERSECT with Other Transact-SQL Statements
- nchar and nvarchar (Transact-SQL)(nchar 和nvarchar说明)
- Hibernate 配置文件precision与scale的作用
- Hibernate 配置文件precision与scale的说法
- 人月神话摘录(2)
- iOS Web 网站开发必备 图标 放大级别 全屏等设置
- 中国压缩传感资源(China Compressive Sensing Resources)
- java 简概时间类
- 普通用户之间的ssh无密码访问设置方法
- Precision, Scale, and Length (Transact-SQL)
- 机器的世界观
- Interview Q&A - 小明一家5口如何过桥?
- python+eclipse
- 转载的mtk笔试
- 杨辉三角
- 河北软件职业技术学院怎么样?CSDN乐知学院
- STL容器用法总结
- 带可变参数的宏函数和普通函数实现