SQL Server : Didn't understand why I can update stat with column/index on the same statistic -


i have read stored procedure update statistic in company have 2 commands update statistic each.

for example

stat name '_wa_sys_00000002_0bc6c43e' 

they have 2 commands update stat

update statistics [dbo].[table_1] [_wa_sys_00000002_0bc6c43e] columns update statistics [dbo].[table_1] [_wa_sys_00000002_0bc6c43e] index 

i think column stat. stat create automatically when create index index stat.

i don't understand why 'update stat index' column stat. , amazing can ran both command.

do have idea? understand correctly?

you have @ official docs when in doubt..

here syntax updating stats..

update statistics table_or_indexed_view_name        [            {                { index_or_statistics__name }             | ( { index_or_statistics_name } [ ,...n ] )                    }       ]        [               [               fullscan                | sample number { percent | rows }                | resample                  [ on partitions ( { <partition_number> | <range> } [, …n] ) ]               | <update_stats_stream_option> [ ,...n ]           ]            [ [ , ] [ | columns | index ]            [ [ , ] norecompute ]            [ [ , ] incremental = { on | off } ]       ] ;   

now taking relevant part..

all | columns | index 

here msdn has this..

update existing statistics, statistics created on 1 or more columns, or statistics created indexes. if none of options specified, update statistics statement updates statistics on table or indexed view.

so when specify columns ,you updating stats on columns ,when specify indexes,you updating stats on index columns..

generally can use below command update stats on columns , indexes default sampling..

exec sp_updatestats;

maintenance work index rebuilds/stats update/any maintenance work done on weekends..so when rebuild indexes , run update stats after rebuilding,you doing double work , countering affect of full scan..

normally when run index rebuild,it rebuilds indexes , update stats on index columns full scan,then run update stats,it again rebuilds stats on index columns , table default sample rate..,which should avoided..this covered benjamin nevarej here

in case can below..

1.run index rebuild
2.now run update stats columns ..

update statistics dbo.salesorderdetail fullscan, columns  

Comments