_대문 | 방명록 | 최근글 | 홈피소개 | 주인놈
FrontPage › 통계정보갱신

데이터베이스의 테이블 중 21% 이상 row가 늘어났는데도 통계 정보가 업데이트 안된 것들...
set nocount on
set statistics io off

declare 
	@tname varchar(255)
,	@sql varchar(2000); 

declare cur cursor for
	select distinct
		c.name + '.' + object_name(b.object_id)
	from sys.sysindexes a
		inner join sys.objects b 
			on a.id = b.object_id
		inner join sys.schemas c
			on b.schema_id = c.schema_id
	where a.rowcnt / a.rowmodctr * 100 >= 21
	and a.rowmodctr > 0
	and a.id > 100
	and a.rowcnt > 1000000
	and c.name not in ('temp')
	and b.type = 'U'

open cur;
fetch next from cur into @tname;
while @@FETCH_STATUS not in (-1, -2)
begin

	set @sql = 'update statistics ' + @tname
	exec(@sql)
	print @sql
		
	fetch next from cur into @tname;
end

close cur;
deallocate cur;

댓글 남기기..
이름: : 오른쪽의 새로고침을 클릭해 주세요. 새로고침
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

우정은 사랑 받는 것 보다 사랑하는 것에 있다. (아리스토텔레스)