当前位置:文档之家› SQL重建索引

SQL重建索引


ALTER proc [dbo].[pt_dbReIndex]
as

/*
--功能:对数据库中索引碎片进行整理
--使用方法:创建存储过程后直接执行:exec pt_dbReIndex
--注意事项:最好在系统空闲时执行
--作者:
--日期:
*/
set nocount on

--定义表名变量
DECLARE @name varchar(100)
set @name=''
--所有用户表游标
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, '', 0)
FETCH NEXT FROM authors_cursor INTO @name
END
--结束游标
close authors_cursor
deallocate authors_cursor
set nocount off

相关主题
文本预览
相关文档 最新文档