I have a transaction which is along the lines of
BEGIN TRANSACTION
INSERT INTO Table2 WITH(TABLOCK)
SELECT BLAH
FROM Table
COMMIT TRANSACTION
This transaction can take up to an hour to complete.
I’d like to run a query a bit like:
SELECT COUNT(*) FROM Table2
at regular intervals on a totally different thread which could report how many rows have been inserted so far.
Is this possible? Is there some way to query for a count of rows which are not committed?
thanks
Add a WITH (NOLOCK) hint to your query.
Take a baseline count before you begin your transaction, then subtract that value from the current number to get the number of newly inserted rows.