SQLServer重建索引

2021/12/1 19:09:47

本文主要是介绍SQLServer重建索引,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Use [数据库名称]

Go 
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 '操作完成!'
go 


DBCC UPDATEUSAGE(0);

转自https://www.cnblogs.com/ruralcraftsman/p/11453604.html



这篇关于SQLServer重建索引的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程