SSMS select count 3billion errors out -

RJ 326 Reputation points
2024-09-23T21:33:22.1833333+00:00

Hi there,

First time one of my tables is 3 Billion records.

When i queried table count in SSMS

select count(*) from table i got the below error.

Does it mean SSMS cant provide row count for tables greater than 2.5 Billion (max int range) rows?

How to go around it? i understand if its year 1999 for SSMS.. but in year 2024?

or is it my setting?

Thanks

{39C9C207-3693-47CD-9148-8A1D499FB0C5}

Community Center | Not monitored
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. hossein jalilian 11,055 Reputation points Volunteer Moderator
    2024-09-23T22:40:27.37+00:00

    Hi RJ,

    Thanks for posting your question in the Microsoft Q&A forum.

    The issue you're encountering with SSMS when trying to count 3 billion records is related to the limitations of the INT data type, which has a maximum value of approximately 2.14 billion.

    The simplest solution is to cast the result to BIGINT

    SELECT CAST(COUNT(*) AS BIGINT) FROM YourTable;
    
    

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 47,441 Reputation points
    2024-09-24T05:24:02.6366667+00:00

    Does it mean SSMS cant provide row count for tables greater than 2.5 Billion (max int range) rows?

    Rigth, therefore you have to use th COUNT_BIG function, it returns the data type bigint, see

    https://learn.microsoft.com/en-us/sql/t-sql/functions/count-big-transact-sql?view=sql-server-ver16

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.