In a system there is a nightly data load process where all the foreign keys are dropped, all tables are truncated, repopulated from an external source, and the foreign keys are put back in place.

At the end of this process I would expect sp_updatestats to run, so that statistics for all this new data is updated.

However, while inspecting the code I noticed the following line instead:


Can you compare that with running sp_updatestats? That is what is the differences and advantages/disadvantages of one over the other?

  • 2
    I'd suggest not using sp_MSforeachtable in general. – LowlyDBA Jan 21 '16 at 21:47
  • @JohnM, yep, why? – Andrew Savinykh Jan 21 '16 at 21:48
  • That's what the link is for :) It's an undocumented stored procedure that can't always be trusted. – LowlyDBA Jan 21 '16 at 21:49
  • @JohnM, silly me! Admit, you sneaked up this link in in the last second! ;) – Andrew Savinykh Jan 21 '16 at 21:51
  • Just expanded the words the link used to make it more obvious – LowlyDBA Jan 22 '16 at 16:18

Couple of things ..

  1. Stop using the undocumented sp_MSforeachtable
  2. From Erin's blog - Understanding What sp_updatestats Really Updates

    sp_updatestats updates only the statistics that require updating based on the rowmodctr information in the sys.sysindexes catalog view, thus avoiding unnecessary updates of statistics on unchanged rows

Note that sp_updatestats in the code sp_helptext sp_updatestats, it runs 'UPDATE STATISTICS '

enter image description here


enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.