Get count while insert is still running

  • I'm running something like this:

    more:

    waitfor delay '00:00:05'

    insert top (1000) into TableB Select *

    from TableA A where A.ID not in (select ID from TableB) -- not already inserted

    if @@rowcount > 0 goto more

    Assuming there are 100,000 records to be inserted (100 loops), should I expect to get a result when it's halfway through if I run:

    select count(*) from TableB with (nolock)

    Or will my count be 0 until it completes ?

    Update: I cancelled the insert, modified some code, and now it seems to be working .... basically: inefficient code.

  • You'll see it as it inserts.

    Not 100% sure you'll get any numbers like 16472 instead of multiples of 1000. But that might be a fun test to setup.

    Care to do it and post the results?

  • It's been running 2 hours and I get 0 🙁

  • homebrew01 (7/26/2011)


    It's been running 2 hours and I get 0 🙁

    What is it waiting on? (sp_WhoIsActive)

  • I have a process to alert me if there's blocking, but no problems so far.

  • Don't know what to tell you. I've definitely done this in the past and I was getting ever increasing counts in the table. I don't know what could be the difference (except that you're looking in the wrong table but I don't dare to suggest that option :w00t:)

  • Ninja's_RGR'us (7/26/2011)


    Don't know what to tell you. I've definitely done this in the past and I was getting ever increasing counts in the table. I don't know what could be the difference (except that you're looking in the wrong table but I don't dare to suggest that option :w00t:)

    I thought I've done it in the past too .... I'm checking the right table .... could be some other brain fart going on with the where clause.

  • Update: I cancelled the insert, modified some code, and now it seems to be working .... basically: inefficient code.

  • Happy to almost have helped :hehe:.

  • Thanks 🙂

  • Can you please share that modified code or share what you have changed!!!!!!!!!

    Thanks

  • Almost 2 years ago at a different company. I don't remember. But since I only displayed sample code, not sure how it would help you.

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply