K3WISE账套优化教程
--账套优化
--作用:重建当前数据库所有用户表索引
DECLARE @DBCCString NVARCHAR(1000)
DECLARE @TableName VARCHAR(100)
DECLARE Cur_Index CURSOR FOR
SELECT Name AS TblName FROM sysobjects WHERE xType='U' ORDER BY TblName
FOR READ ONLY
OPEN Cur_Index
FETCH NEXT FROM Cur_Index INTO @TableName
WHILE @@FETCH_STATUS=0
BEGIN
SET @DBCCString = 'DBCC DBREINDEX(@TblName,'''')WITH NO_INFOMSGS'
EXEC SP_EXECUTESQL @DBCCString,N'@TblName VARCHAR(100)',@TableName
PRINT '重建表' + @TableName +'的索引........OK!'
FETCH NEXT FROM Cur_Index INTO @TableName
END
CLOSE Cur_Index
DEALLOCATE Cur_Index
PRINT '操作完成!'
--更新统计信息
declare @SqlStr1 nvarchar(max)
set @SqlStr1=''
select @SqlStr1= @SqlStr1+ + 'UPDATE STATISTICS '+name+ ';' from sysobjects where xtype='U' and (name like 'T_%') and (name not like 'TMP%')
exec (@SqlStr1)