Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

EXEC sp_MSforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN'

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

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

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

Recommendation:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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