SQL Server error 8115: Arithmetic overflow error converting
A number is too big for the target data type, for example a value over 2,147,483,647 into int, or more digits than a decimal's precision allows.
- Error number
8115- Severity
- 16
- Category
- Data conversion and truncation
What it means
Each numeric type has a range: tinyint 0 to 255, smallint up to 32,767, int up to 2,147,483,647, and decimal(p, s) at most p digits with s after the decimal point. Converting a value that doesn't fit, explicitly or implicitly, raises 8115. A common surprise is COUNT(*) or SUM() over an int column exceeding the int range on big tables.
Common causes
- Inserting or converting a value that is larger than the column type allows.
SUM()of anintcolumn whose total passes 2,147,483,647; the result type isint.COUNT(*)on more than about 2.1 billion rows (useCOUNT_BIG).- Converting to a
decimalwith too few digits, such as 1234.5 intodecimal(4,1). - An identity column of type
intthat has run out of values.
How to fix it
-
Aggregate in a wider type.
SELECT SUM(CAST(Quantity AS bigint)) AS total, COUNT_BIG(*) AS row_count FROM dbo.OrderLines;
-
Widen the column to
bigintor a largerdecimal.ALTER TABLE dbo.Metrics ALTER COLUMN Value decimal(18, 4) NOT NULL;
-
Check how close an identity column is to its limit.
SELECT IDENT_CURRENT('dbo.Events') AS current_identity;
Reproduce it safely
SELECT CAST(300 AS tinyint); -- Msg 220 for a constant; with a column or decimal it is 8115: SELECT CAST(1234.5 AS decimal(4, 1)); -- Msg 8115
Related errors
220Arithmetic overflow error for data type8114Error converting data type245Conversion failed converting a value22003PostgreSQL: numeric value out of range1264MySQL: Out of range value for columnORA-01438Oracle: value larger than specified precision
More data conversion and truncation errors
8152String or binary data truncated2628Truncated in table, column241Conversion failed for date and/or time242Out-of-range date conversion512Subquery returned more than 1 value8134Divide by zero error encountered248Conversion overflowed an int column8169Conversion to uniqueidentifier failed
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.