[转帖]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 还有这种功能 感觉类似于 ...
随机推荐
- Linux的发行版及其描述
Linux的十种发行版及其描述 linux其中十种发行版本为Debian.Gentoo.Ubuntu.Damn Vulnerable Linux.红帽企业级Linux. CentOS.Fedora.K ...
- 高性能利器!华为云MRS ClickHouse重磅推出!
摘要:华为智能数据湖MRS服务即将上线ClickHouse高性能引擎集群,用户只需要几分钟,就可以轻松方便地一键式完成集群部署搭建,快速拥有PB级数据的秒级交互查询分析能力,帮助用户带来极致的性能体验 ...
- 一文带你了解两种Transformer文字识别方法
摘要:受Transformer模型的启发,目前一些学者将该结构应用到文本行识别中,以替代RNN,取得了良好的效果,如在HGA-STR和 SRN. 当前的文本行识别器为拥有更强的序列语义能力,模型多采用 ...
- AI开发效率低,你可以试试华为NAIE AutoML
摘要:为解决AI工程师在开发AI应用场景所遇到的问题,NAIE平台落地AutoML框架(工具)来辅助大家更高效.更迅速解决AI开发问题. 你是不是还在为掌握的AI算法少而烦恼? 你是不是还在为选择某个 ...
- Docker Jenkins 安装配置
Docker Jenkins 安装配置 Windows 2016 安装 Jenkins Jenkins + SVN Jenkins + SVN/Git + Maven + Docker + 阿里云镜像 ...
- 微软的一些公开课,Python、机器学习、SQL、AI,全部免费
大家好,我是老章,刷X看到一位博主Alif Hossain@alifcoder总结了微软的一些公开课,全部免费,蛮不错的.感兴趣可以学一波,还能领徽章. 1. 机器学习简介 本课程是学习机器学习基础知 ...
- 遇事不决,量子力学;不懂配色,赛博朋克。推荐一个Python可视化库
遇事不决,量子力学;不懂配色,赛博朋克.推荐一个Python可视化库 12月10日,历经多次跳票后,波兰公司CD Projekt Red制作的<赛博朋克2077>终于正式发售,在Steam ...
- Linux day4:查看文件属性信息 inode和block 硬链接和软链接 inux系统时间 虚拟机克隆 linux定时任务 paramiko模块 公钥私钥
目录 文件属性信息 存储数据相关 inode block 访问文件原理 链接信息 硬链接 软链接 linux系统时间 虚拟机克隆 链接克隆和完整克隆 克隆之后的配置 linux定时任务 定时任务软件 ...
- Ajax请求 content_type ajax发送Fromdata对象
目录 Ajax请求入门 ajax实现简单计算器 content_type urlencode fromdata application/json 自定义request.JSON ajax发送Fromd ...
- 极限五分钟,在宝塔中用 Docker 部署升讯威在线客服系统
我在业余时间开发维护了一款免费开源的升讯威在线客服系统,也收获了许多用户.对我来说,只要能获得用户的认可,就是我最大的动力. 最近客服系统成功经受住了客户现场组织的压力测试,获得了客户的认可. 客户组 ...