How to show query percentage or progress in SQL Server 2012 (SP4)?

Mark Miller 0 Reputation points
2023-05-01T13:58:48.9366667+00:00

How to show query percentage or progress in SQL Server 2012 (SP4)? I have a very large purge query running: Total Number Txns To Be Purged: 124549981. The db is 588GB. I know the Live View didn't come along until Sql Server 2014 or 2016. Thanks.

SQL Server Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2023-05-01T14:44:22.62+00:00

    How are you running the purge? Is it one single statement? For this large amount of data, it is often a good idea to split up the work in chunks of, say, five millions rows at time. If you do this, showing progress becomes a trivial matter. Important! If you do things in chunks, you need an index to support your chunk condition, so that you don't have to scan the big table for every chunk.

    If you are running all as one statement, about the only option is to run a

    SELECT COUNT(*) FROM tbl WITH (NOLOCK) WHERE ... 
    

    to get an idea of the progress. This is one of the few situations where NOLOCK actually is useful.


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.