DECLARE
UpdateStatisticsTables CURSOR
READ_ONLY FOR |
02 | SELECT
sst.name,
|
03 | Schema_name(sst.schema_id)
|
04 | FROM
sys.tables sst |
05 | WHERE
sst.TYPE = 'U' |
06 | DECLARE
@name VARCHAR(80),
|
07 | @schema
VARCHAR(40) |
08 |
09 | OPEN
UpdateStatisticsTables |
10 |
11 | FETCH
NEXT FROM UpdateStatisticsTables
INTO @name, @schema |
12 |
13 | WHILE ( @@FETCH_STATUS <> -1 )
|
14 | BEGIN |
15 | IF ( @@FETCH_STATUS <> -2 )
|
16 | BEGIN |
17 | DECLARE
@sql NVARCHAR(1024) |
18 | SET
@sql='UPDATE STATISTICS '
+ Quotename(@schema)
|
19 | +
|
20 | '.'
+ Quotename(@name) |
21 | EXEC
Sp_executesql @sql |
22 | END |
23 |
24 | FETCH
NEXT FROM
UpdateStatisticsTables INTO
@name, @schema |
25 | END |
26 |
27 | CLOSE
UpdateStatisticsTables |
28 |
29 | DEALLOCATE
UpdateStatisticsTables |
30 |
31 | GO |
本文介绍了一个用于SQL Server的存储过程,该过程能够遍历所有用户表并更新其统计信息,以此来优化查询计划及提高查询效率。

被折叠的 条评论
为什么被折叠?



