![](/img/trans.png)
[英]INDEX rebuild and reorganize based on fragmentation results in SQL Server 2012
[英]SQL Index Rebuild: Index Fragmentation % Increases?
我正在嘗試創建一個代理作業,該作業將為連接到Deltek 6.1接口的SQL 2008 R2數據庫重建索引。
正在運行:
exec sp_msforeachtable 'DBCC DBREINDEX("?"," ",0)'
注意到某些索引實際上變得越來越零散。 難道是由於索引間距? 我們已經通過各種不同的重建方法在測試和生產網絡上發生了這種情況。 表通常很大,我們在運行重建后更新統計信息。
用於在SQL Server中重建所有表索引的腳本:
USE DatabaseName --Enter the name of the database you want to reindex
DECLARE @TableName varchar(255)
DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName,' ',90)
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.