重建索引sp_RebuildIdxes
时间:2011-04-29 来源:Jefft
create PROC [dbo].[sp_RebuildIdxes] @tblName SYSNAME = '%'
AS
SET NOCOUNT ON
DECLARE @str NVARCHAR(1000)
DECLARE curTbls CURSOR FOR
SELECT Name FROM sysobjects
WHERE OBJECTPROPERTY(OBJECT_ID(Name),'IsUserTable')=1
AND Name LIKE @tblName
OPEN curTbls
FETCH curTbls INTO @tblName
WHILE @@Fetch_Status=0
BEGIN
PRINT CHAR(13) + 'Rebuild index:' + @tblName
SET @str='DBCC DBREINDEX([' + @tblName + '])'
EXEC(@str)
FETCH curTbls INTO @tblName
END
CLOSE curTbls
DEALLOCATE curTbls
RETURN 0
相关阅读 更多 +