Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why SQL Server throws Arithmetic overflow error converting int to data type numeric?

I have an error being thrown by SQL Server Management Studio when running this code:

declare @percentage numeric(3,2) set @percentage = cast(15 as numeric(3,2)) 

but when I change numeric declaration to

declare @percentage numeric(4,2) set @percentage = cast(15 as numeric(4,2)) 

everything goes fine.

Is there a limitation for numeric data type?

like image 841
Junior Mayhé Avatar asked Jan 13 '10 18:01

Junior Mayhé


People also ask

What does arithmetic overflow error convert to data type int mean?

1. "Arithmetic overflow error converting IDENTITY to data type int" error means the value of IDENTITY is overflowing range of data type of that particular column. 2. Check the current value of Identity.

How can we avoid arithmetic overflow in SQL?

The solution to avoid this arithmetic overflow error is to change the data type from INT to BIGINT or DECIMAL(11,0) for example.

What is arithmetic overflow in SQL?

The error "Arithmetic overflow error converting IDENTITY to data type int" comes when IDENTITY value is inserted into a column of data type int, but the value is out-of-range.

What is meant by arithmetic overflow?

An arithmetic overflow is the result of a calculation that exceeds the memory space designated to hold it. For example, a divide-by-zero yields a much larger result.


1 Answers

Numeric defines the TOTAL number of digits, and then the number after the decimal.

A numeric(3,2) can only hold up to 9.99.

like image 154
Joe Avatar answered Sep 17 '22 14:09

Joe