Here is my query:
SELECT COUNT(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0
Here is the result:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
The table has 4 billion rows. I don't expect this query to be fast, but after about 5mins, it fails with an overflow error. Is there a COUNT
function for bigger data than int?
Thanks.
You need to increase the width of the variable to store this number e.g. making @sample NUMERIC (6,2) will solve this error.
The solution to avoid this arithmetic overflow error is to change the data type from INT to BIGINT or DECIMAL(11,0) for example.
COUNT(*) returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.
In general, a data type overflow error is when the data type used to store data was not large enough to hold the data. Furthermore, some data types can only store numbers up to a certain size. An overflow error will be produced, for example, if a data type is a single byte and the data to be stored is greater than 256.
Use COUNT_BIG
SELECT COUNT_BIG(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0
SELECT COUNT_BIG(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With