SQL SERVER 索引维护

-- 全数据库索引重建

DECLARE @name varchar(100)
DECLARE authors_cursor CURSOR FOR Select [name] from sysobjects where xtype='u' order by id
OPEN authors_cursor
FETCH NEXT FROM authors_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
 DBCC DBREINDEX (@name, '', 90)
FETCH NEXT FROM authors_cursor INTO @name
END
deallocate authors_cursor

 

-- 单表数据库维护

-- 单表重建索引

dbcc dbreindex('表名',索引名称,100)

 

-- 查看表索引密集度

declare @table_id int
set @table_id=object_id('表名称')
dbcc showcontig(@table_id)

 

--参数说明,第三个参数表示填充因子

低更改的表(读写比率为100:1):100%的填充因子
高更改的表(写超过读):50-70%的填充因子
读写各一半的:80-90%的填充因子

-- 数据库检查碎片

DBCC ShowContig
DBCC ShowContig(表名)

posted @ 2017-02-21 10:03  chengeng  阅读(128)  评论(0编辑  收藏  举报