views:

1991

answers:

4

I'm wondering if updating statistics has helped you before and how did you know to update them?

+3  A: 
exec sp_updatestats

Yes, updating statistics can be very helpful if you find that your queries are not performing as well as they should. This is evidenced by inspecting the query plan and noticing when, for example, table scans or index scans are being performed instead of index seeks. All of this assumes that you have set up your indexes correctly.

There is also the UPDATE STATISTICS command, but I've personally never used that.

Ben Hoffstein
From BOL: sp_updatestats effectively executes UPDATE STATISTICS, by specifying the ALL keyword, against all user-defined and internal tables in the database.
Mitch Wheat
+2  A: 

It's common to add your statistics update to a maintenance plan (as in an Enterprise Manager-defined Maintenance plan). That way it happens on a schedule - daily, weekly, whatever.

SQL Server 2000 uses statistics to make good decisions about query execution so they definitely help.

It's a good idea to rebuild your indexes at the same time (DBCC DBREINDEX and DBCC INDEXDEFRAG).

Corbin March
+1  A: 

Updating statistics becomes necessary after the following events:
- Records are inserted into your table
- Records are deleted from your table
- Records are updated in your table

If you have a large database with millions of records that gets lots of writes per day you probably should be determining an off-peak time to schedule index updates.

Also, you need to consider your type of traffic. If you have a lot (millions) of records in tables with many foreign key dependencies and you have a larger proportion of writes to reads you might want to consider turning off automatic statistics recomputation (NOTE: this feature will be removed in a future version of SQL Server, but for SQL Server 2000 you should be OK). This tells the engine to not recompute statistics on every INSERT, DELETE, or UPDATE and makes those actions much more performant.

Indexes are no laughing matter. They are the heart and soul of a performant database.

KG
+1  A: 

If you rebuild indexes, then the statistics for those indexes are automatically rebuilt. If your timeframes allow, then running UPDATE STATISTICS of part of a maintenance plan is a good idea, as frequently as nightly (if your indexes are being rebuilt less frequently than that).

SQL Server: To determine if out of date statistics are the cause of a query performing poorly, turn on 'Query->Display Estimated Execution plan' (CTRL-L) in Management Studio and run the query. Open another window, paste in the same query and turn on 'Query->Display ActualExecution plan' (CTRL-M) in Management Studio and re-run the query. If the execution plans are different then statistics are most likely out of date.

Mitch Wheat