sql server重建数据库所有表索引

重建索引:

DECLARE @name nvarchar(255)

–所有用户表游标
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, ‘’, 70)
– Get the next author.
FETCH NEXT FROM authors_cursor INTO @name
END

CLOSE authors_cursor
DEALLOCATE authors_cursor

go

#查看表索引碎片情况

use nfsscmuat
–创建变量 指定要查看的表
declare @table_id int
set @table_id=object_id(‘Instore’)
–执行
dbcc showcontig(@table_id)


版权声明:本文为weixin_43069201原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。