"Arithmetic overflow error converting..." (Msg 8115)
A value doesn't fit the target integer type's range. SQL Server enforces every declared width strictly; SQLite enforces none of them at all.
- SQL Server:
Msg 8115, Level 16, State 2followed byArithmetic overflow error converting expression to data type tinyint.(the target type named varies:int,smallint,numeric, ...) - PostgreSQL:
ERROR: smallint out of range - MySQL (strict mode):
Out of range value for column 'x' at row 1
SQLite doesn't even participate — it has no fixed-width integer types to overflow in the first place:
Loading editor…
TINYINT is SQL Server's 1-byte unsigned type — its actual range is
0-255. 300 doesn't fit. On SQL Server this errors outright; above, SQLite
just returns 300 unchanged.
The cause
SQLite's type system uses type affinity, not enforced storage width —
TINYINT, SMALLINT, INT, and BIGINT are all the same underlying
8-byte signed integer storage in SQLite; the declared width is accepted
as valid syntax and then ignored completely. SQL Server's integer types
are real, fixed-width storage with a real range, and every arithmetic
result, explicit CAST/CONVERT, or implicit conversion into one is
checked against that range:
| Type | Range |
|---|---|
tinyint | 0 to 255 |
smallint | -32,768 to 32,767 |
int | -2,147,483,648 to 2,147,483,647 |
bigint | ±~9.2 × 10¹⁸ |
The three places this actually bites
An explicit CAST/CONVERT — the obvious case above: the source
value is simply bigger than the target type can hold.
An aggregate whose result exceeds the type of the column being
summed — SUM() over an int column returns int, not a wider type,
so summing enough mid-size values can overflow even though every
individual row was fine:
-- each row fits easily in int, but the SUM() doesn't
SELECT SUM(amount) FROM orders; -- errors if the total exceeds ~2.1 billion
-- fix: widen the column, or cast before aggregating
SELECT SUM(CAST(amount AS BIGINT)) FROM orders;An IDENTITY column reaching its type's ceiling — a different
variant of the same message
(Arithmetic overflow error converting IDENTITY to data type int): once
an int IDENTITY column has issued its 2,147,483,647th value, the next
insert fails this way, not a constraint violation. Check how close a
column actually is before it becomes a production incident:
SELECT IDENT_CURRENT('orders'), 2147483647 - IDENT_CURRENT('orders') AS headroom;The fix
Widen the type — bigint instead of int, int instead of smallint
— on whichever side of the conversion is too narrow. For an IDENTITY
nearing its ceiling specifically, widening the column's type is usually
cheaper up front than a full re-key, but changing an IDENTITY column's
type on a large, actively-written table is itself a real migration — plan
a maintenance window, not a quick ALTER COLUMN.
Why this matters beyond SQLite itself
The same risk from the VARCHAR-length page applies here identically: a schema with narrow integer types that's been developed and tested against SQLite will never once produce this error locally, no matter how large the test data gets — the type declarations are present but inert. The first real overflow shows up in production, against real data volume, on the engine that was actually enforcing the range the whole time.
- String or binary data would be truncated — the same "SQLite accepts the declaration, enforces nothing" gap, for string length instead of integer range.
- Data type precedence checker — which type wins when two different ones meet in an expression, a related but distinct question from whether a value fits one type's range.
- Type coercion — conversions in general, implicit and explicit.
CAST(40000 AS SMALLINT) instead — SQLite still returns it unchanged, even though SQL Server's smallint tops out at 32,767.Open the playground →