重建索引:
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)
本文介绍了一种使用T-SQL脚本对SQL Server数据库进行索引优化的方法,包括重建索引和检查索引碎片,以提高数据库性能。

3074

被折叠的 条评论
为什么被折叠?



