您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_fixindex

语法


sp_fixindex <database_name>, <table_name>[, <index_id> | null] 
	[, <index_name> | null] [, force_option]

参数

<dbname>

是数据库名称

<tabname>

是表名

<indiex_id>

是要修复的索引的 ID

<index_name>

指示需要处理的索引。如果使用 NULL 值,则会重建与 <index_id> 关联的索引。如果 <index_id> 也为 NULL 值,则将重建系统表中的所有索引

force_option

强制 SAP ASE 服务器重建 tempdb 中的系统表索引。不带 force_option 的 sp_fixindex 将强制 <database_name> 指定的数据库处于单用户模式,这是 tempdb 无法实现的。虽然 force_option 允许重建 tempdb 中的系统目录,但不应将其用于用户数据库。

示例

示例 1

修复 pubs2 数据库的 sysprocedures 表上的聚簇索引:


sp_fixindex pubs2, sysprocedures, 1

示例 2

重建 testdb..sysprocedures 上索引 ID 为 2 的索引:


sp_fixindex 'testdb', 'sysprocedures', 2

示例 3

重建 testdb..sysprocedures 系统表中的索引 csysprocedures:


sp_fixindex 'testdb', 'sysprocedures', null, 'csysprocedures'

示例 4

重建 testdb 中的 sysprocedures 表上的所有可用索引。如果该表具有聚簇或位置索引,sp_fixindex 将通过删除数据页中存在的碎片来回收未使用的空间(即重建数据页):


sp_fixindex 'testdb', 'sysprocedures'

示例 5

重建 tempdb..sysprocedures 上索引 ID 为 2 的索引:


sp_fixindex 'tempdb', 'sysprocedures', 2, null, 1

示例 6

重建表 tempdb..sysprocedures 的索引 csysprocedures:


sp_fixindex 'tempdb', 'sysprocedures', null,
    'sysprocedures', 1

示例 7

重建 tempdb 中的 sysprocedures 上的所有索引:


sp_fixindex 'tempdb', 'sysprocedures', null, null, 1

用法

在运行 sp_fixindex 之前,确保您的数据库处于单用户模式并重新配置数据库以允许更新系统表。

运行 sp_fixindex 后:

  • 使用 dbcc checktable 命令验证损坏的索引已被修复

  • 使用 sp_configure 禁止更新系统表

  • 关闭单用户模式

    不要在用户表上运行 sp_fixindex。

    警告

    不能对 sp_fixindex 上的聚簇索引使用 sysindexes。否则 sp_fixindex 将返回以下错误消息:

    不能在此表上重新创建索引。