[转帖]decimal and numeric (Transact-SQL)
- https://learn.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql?view=sql-server-ver16
Applies to: SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL Endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
Numeric data types that have fixed precision and scale. Decimal and numeric are synonyms and can be used interchangeably.
Arguments
decimal[ (p[ ,s] )] and numeric[ (p[ ,s] )]
Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). numeric is functionally identical to decimal.
p (precision)
The maximum total number of decimal digits to be stored. This number includes both the left and the right sides of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.
Note
Informatica only supports 16 significant digits, regardless of the precision and scale specified.
s (scale)
The number of decimal digits that are stored to the right of the decimal point. This number is subtracted from p to determine the maximum number of digits to the left of the decimal point. Scale must be a value from 0 through p, and can only be specified if precision is specified. The default scale is 0 and so 0 <= s <= p. Maximum storage sizes vary, based on the precision.
| Precision | Storage bytes |
|---|---|
| 1 - 9 | 5 |
| 10-19 | 9 |
| 20-28 | 13 |
| 29-38 | 17 |
Note
Informatica (connected through the SQL Server PDW Informatica Connector) only supports 16 significant digits, regardless of the precision and scale specified.
Converting decimal and numeric data
For decimal and numeric data types, SQL Server considers each combination of precision and scale as a different data type. For example, decimal(5,5) and decimal(5,0) are considered different data types.
In Transact-SQL statements, a constant with a decimal point is automatically converted into a numeric data value, using the minimum precision and scale necessary. For example, the constant 12.345 is converted into a numeric value with a precision of 5 and a scale of 3.
Converting from decimal or numeric to float or real can cause some loss of precision. Converting from int, smallint, tinyint, float, real, money, or smallmoney to either decimal or numeric can cause overflow.
By default, SQL Server uses rounding when converting a number to a decimal or numeric value with a lower precision and scale. Conversely, if the SET ARITHABORT option is ON, SQL Server raises an error when overflow occurs. Loss of only precision and scale isn't sufficient to raise an error.
Prior to SQL Server 2016 (13.x), conversion of float values to decimal or numeric is restricted to values of precision 17 digits only. Any float value less than 5E-18 (when set using either the scientific notation of 5E-18 or the decimal notation of 0.000000000000000005) rounds down to 0. This is no longer a restriction as of SQL Server 2016 (13.x).
Examples
The following example creates a table using the decimal and numeric data types. Values are inserted into each column. The results are returned by using a SELECT statement.
CREATE TABLE dbo.MyTable
(
MyDecimalColumn DECIMAL(5,2)
,MyNumericColumn NUMERIC(10,5)
);
GO
INSERT INTO dbo.MyTable VALUES (123, 12345.12);
GO
SELECT MyDecimalColumn, MyNumericColumn
FROM dbo.MyTable;
Here is the result set.
MyDecimalColumn MyNumericColumn
--------------------------------------- ---------------------------------------
123.00 12345.12000
(1 row(s) affected)
[转帖]decimal and numeric (Transact-SQL)的更多相关文章
- SQL中的real、float、decimal、numeric数据类型区别
概述: 浮点数据类型包括real型.float型.decimal型和numeric型.浮点数据类型用于存储十进制小数. 在SQL Server 中浮点数值的数据采用上舍入(Round up)的方式进行 ...
- decimal 和 numeric (Transact-SQL)
decimal(18,0)18是定点精度,0是小数位数.decimal(a,b)a指定指定小数点左边和右边可以存储的十进制数字的最大个数,最大精度38.b指定小数点右边可以存储的十进制数字的最大个数. ...
- 关于MSSQL的decimal(numeric)、money、float的使用以及区别
decimal(numeric).money.float(real) 都是MSSQL中的浮点类型的数据类型. 按存储的范围进行排序 float(real) decimal(numeric) money ...
- Sql server decimal 和 numeric
带固定精度和小数位数的数值数据类型. decimal[ (p[ , s] )] 和 numeric[ (p[ , s] )] 固定精度和小数位数.使用最大精度时,有效值从 - 10^38 +1 到 1 ...
- sql server中的decimal或者numeric的精度问题
何谓精度:最多可以存储的十进制数字的总位数,包括小数点左边和右边的位数.该精度必须是从 1 到最大精度 38 之间的值.默认精度为 18. 小数位数:小数点右边可以存储的十进制数字的最大位数.小数位数 ...
- (转载)mysql decimal、numeric数据类型
(转载)http://www.cnblogs.com/qiantuwuliang/archive/2010/11/03/1867802.html 可能做程序的人都知道,float类型是可以存浮点数(即 ...
- mysql中 decimal、numeric数据类型
例 如:salary DECIMAL(5,2) 在这个例子中,5 (精度(precision)) 代表重要的十进制数字的数目,2 (数据范围(scale)) 代表在小数点后的数字位数.在这种情况下,因 ...
- [转帖]真TM长的:SQL Server 2008存储结构——GAM和SGAM、PFS结构、IAM结构、DCM&BCM
谈到GAM和SGAM,我们不得不从数据库的页和区说起. https://blog.csdn.net/snowfoxmonitor/article/details/49991015 一个数据库由用户定义 ...
- [转帖]PG语法解剖--基本sql语句用法入门
PG语法解剖--基本sql语句用法入门 https://www.toutiao.com/i6710897833953722894/ COPY 命令挺好的 需要学习一下. 原创 波波说运维 2019-0 ...
- [转帖]使用TOAD优化复杂SQL
独家秘笈!看下如何一键优化Oracle数据库复杂sql,DBA必备 https://www.toutiao.com/i6741208493644055053/ 原来toad 还有这种功能 感觉类似于 ...
随机推荐
- 文心一言 VS 讯飞星火 VS chatgpt (173)-- 算法导论13.3 2题
二.用go语言,将关键字41.38.31.12.19.8连续地插入一棵初始为空的红黑树之后,试画出该结果树. 文心一言: 首先,我们需要了解红黑树的性质.红黑树是一种自平衡二叉查找树,其中每个节点要么 ...
- super只能用在构造方法里面吗?
super关键字并不仅限于在构造方法中使用.在Java中,super关键字有两个主要的用途: 在子类的构造方法中调用父类的构造方法.这是super的一个常见用法,通常是在子类的构造方法的第一行使用,用 ...
- 创建傀儡进程svchost.exe并注入DLL文件(Shellcode)
本文主要利用 SetThreadContext 修改进程中的线程上下文来实现Dll注入(ShellCode). 实现原理 首先,使用 CreateProcess 函数创建svchost.exe进程,并 ...
- .NET Core Swagger Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround
遇到的问题 因为新增了一个控制器方法,从而导致在运行Swagger的时候直接报错,异常如下: SwaggerGeneratorException: Conflicting method/path co ...
- 微信小程序中业务域名的配置
需要配置业务域名,需要先将域名http转https 1,首先在该微信小程序的公众号平台中下载 业务域名的证书 2,将下载的证书放进nginx的根目录 3,在nginx中 (root为.txt的地址)
- Spring Boot 应用部署流程
在本机操作,执行以下步骤启动项目 1.从Github上下载源码 git clone https://github.com/ChinaSilence/any-video.git 2.在数据库中建库,建表 ...
- C++篇:第四章_数组_知识点大全
C++篇为本人学C++时所做笔记(特别是疑难杂点),全是硬货,虽然看着枯燥但会让你收益颇丰,可用作学习C++的一大利器 四.数组 (一)数组标准 以数组名作函数参数时,实参数组与形参数组都不必定义长度 ...
- 昇腾携手OpenMMLab,支持海量算法仓库的昇腾AI推理部署
摘要:近日,昇腾AI联合上海人工智能实验室,正式实现OpenMMLab算法仓库在昇腾的异构计算架构CANN上的推理部署,目前相关代码已推入MMDeploy 0.10.0版本,并在GitHub正式发布. ...
- 云图说丨初识分布式消息服务Kafka版
摘要:分布式消息服务Kafka版是一款基于开源社区版Kafka提供的消息队列服务,向用户提供计算.存储和带宽资源独占式的Kafka实例. 本文分享自华为云社区<[云图说]第254期 初识分布式消 ...
- 火山引擎 DataLeap 助你拥有 Notebook 交互式的开发体验
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 Notebook 是一种支持 REPL 模式的开发环境.所谓「REPL」,即「读取-求值-输出」循环:输入一段 ...