- 眾所周知隨着表的數據量不斷增長,會產生很多索引的碎片。這時候需要重建索引來提高查詢性能。
USE [DBName] 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 --將游標向下移1行,獲取的數據放入之前定義的變量@name WHILE @@FETCH_STATUS = 0 -- 正常讀取 BEGIN DBCC DBREINDEX (@name, '', 90) FETCH NEXT FROM authors_cursor INTO @name END deallocate authors_cursor --釋放游標
- 你也可以把腳本執行計划設置到定時執行任務計划之內