반응형

/********************************************************************************************
-- Title : [SQL2012] 30일 이전에 통계 업데이트된 리스트 추출
-- Key word : dbcc show_statistics update statistics sp_autostats 통계 업데이트 통계 확인
********************************************************************************************/

-- 오늘 기준으로 30일 이전의 통계 리스트 추출
declare @dt tinyint;
set @dt = 30; --▶ 오늘부터 특정일 이전 지정

declare @rslt table
( ident int not null identity
, tbl_nm sysname not null
, stats_nm sysname not null
, stats_upd_dt datetime null
);

insert into @rslt
exec sp_MSForEachTable
'SELECT ''?'' "TNL_NAME", name "IDX_NM",
        STATS_DATE(object_id, stats_id) AS statistics_update_date
 FROM sys.stats
 WHERE object_id = OBJECT_ID(''?'');
';

select ident, replace(replace(tbl_nm, '[', ''), ']', '') "tbl_nm", stats_nm, stats_upd_dt
from @rslt
where getdate() - @dt > stats_upd_dt
order by 2,3;

-- 통계 확인
dbcc show_statistics('sch_test.test_tbl', ix_test_tbl);

-- 통계 업데이트
update statistics sch_test.test_tbl with norecompute;
exec sp_autostats 'sch_test.test_tbl', 'on';

 

반응형

+ Recent posts