[转帖]decimal and numeric (Transact-SQL)

decimal,and,numeric,transact,sql · 浏览次数 : 0

小编点评

**Decimal and Numeric Data Types** **Data Type** | **Fixed Precision and Scale** | **Maximum Total Number of Decimal Digits** | ---|---|---| decimal | 1-38 | 18 | numeric | Same as decimal | Same as decimal |

正文

  1. 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(ps). 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.

PrecisionStorage 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.

SQL
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.

SQL
MyDecimalColumn                         MyNumericColumn  
--------------------------------------- ---------------------------------------  
123.00                                  12345.12000  
  
(1 row(s) affected)  

与[转帖]decimal and numeric (Transact-SQL)相似的内容:

[转帖]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 Databas

[转帖]12.24.2 DECIMAL Data Type Characteristics

https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html This section discusses the characteristics of the DECIMAL data type (and its synonyms),

[转帖]decimal,float和double的区别是什么?

https://zhuanlan.zhihu.com/p/352503879 今天复习mysql理论知识,在看常用数据类型的时候发现float和decimal类型都是表示小数,就展开搜索学习了一下区别,分享给大家: 表示小数的一共有三种类型:float是单精度,double是双精度,decimal是

[转帖]MySQL Decimal 的实现方法

码: 背景 数字运算在数据库中是很常见的需求, 例如计算数量、重量、价格等, 为了满足各种需求, 数据库系统通常支持精准的数字类型和近似的数字类型. 精准的数字类型包含 int, decimal 等, 这些类型在计算过程中小数点位置是固定的, 其结果和行为比较可预测. 当涉及钱时, 这个问题尤其重要

[转帖]MySQL: Convert decimal to binary

Last Update:2018-12-05 Source: Internet Author: User Tags decimal to binary mysql code Developer on Alibaba Coud: Build your first app with APIs, SDKs

[转帖]MySQL数据类型(decimal的存储大小)

本来还以为MySQL的数据类型挺简单的,没想到竟然有很多坑,容我仔细道来 MySQL数据类型 整数类型(注意是字节) 浮点型(重点关注decimal) 字符型(注意这是4.x版本的定义,5.x以后已经将其中的字节转换成字符了) 日期类型 MySQL日期类型表示方法与字符串的表示方法相同(用单引号括起

[转帖]MySQL定点数类型DECIMAL用法详解

https://www.cnblogs.com/danielzzz/p/16824214.html 一、MySQL DECIMAL 的使用 DECIMAL 数据类型用于在数据库中存储精确的数值,我们经常将该数据类型用于保留准确精确度的列,例如会计系统中的货币数据。 要定义数据类型为DECIMAL的列

[转帖]

Linux ubuntu20.04 网络配置(图文教程) 因为我是刚装好的最小系统,所以很多东西都没有,在开始配置之前需要做下准备 环境准备 系统:ubuntu20.04网卡:双网卡 网卡一:供连接互联网使用网卡二:供连接内网使用(看情况,如果一张网卡足够,没必要做第二张网卡) 工具: net-to

[转帖]

https://cloud.tencent.com/developer/article/2168105?areaSource=104001.13&traceId=zcVNsKTUApF9rNJSkcCbB 前言 Redis作为高性能的内存数据库,在大数据量的情况下也会遇到性能瓶颈,日常开发中只有时刻

[转帖]ISV 、OSV、 SIG 概念

ISV 、OSV、 SIG 概念 2022-10-14 12:29530原创大杂烩 本文链接:https://www.cndba.cn/dave/article/108699 1. ISV: Independent Software Vendors “独立软件开发商”,特指专门从事软件的开发、生产、