`

sqlserver重建索引

阅读更多
第一步:查看是否需要维护,查看扫描密度/Scan Density是否为100%
declare @table_id int
set @table_id=object_id('表名')
dbcc showcontig(@table_id)


第二步:重构SQL Server数据库表索引
dbcc dbreindex('表名',pk_索引名,100)


重做第一步,如发现扫描密度/Scan Density还是小于100%则重构表的所有索引,并不一定能达100%。
dbcc dbreindex('表名','',100)


重建数据库所有表的索引
USE database_name; 

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics