查找并修复损坏的索引
ASE将索引标记为“可疑”时,或者ASE的排序顺修改后,索引状态会设置:-32768,
patrol指标SuspectIndex会监控数据库中可疑索引的个数。
查找出现索引索引损坏的表:
	
存储过程:sp_indsuspect [table_name]
如果不加表名,就是查找当前数据库中因排序顺序更改需被重建的索引的所有表;
或:
select u.name as user_name, o.name as table_name, i.name as index_name,i.status
	from  sysobjects o,  sysindexes i,  sysusers u
	where   o.id = i.id   and o.uid = u.uid
	  --and o.id = object_id('table_name')
	  and (i.status & -32768) != 0
例子:
	
1> sp_indsuspect
	2> go
	Suspect indexes in database dbainfo:
	 Own.Tab.Ind (Obj_ID, Ind_ID)
	 ----------------------------------------------
	 dbo.sysqueryplans.csysqueryplans (27, 2)
	 dbo.sysqueryplans.ncsysqueryplans (27, 3)
修复索引:
建议使用dbcc reindex ({table_name | table_id})
当dbcc reindex发现损坏的索引时,它会删除并重新创建相应的索引。dbcc reindex不会重建系统表的索引。
生成重建用户表索引命令的SQL语句:
select distinct 'dbcc reindex('''|| u.name || '.' ||  o.name  || ''')'
	from  sysobjects o,  sysindexes i,  sysusers u
	where   o.id = i.id   and o.uid = u.uid
	  --and o.id = object_id('table_name')
	  and (i.status & -32768) != 0
索引重建时间:
	
系统表sysindexes中有字段crdate记录索引的创建时间。使用dbcc reindex重建索引后,可以通过查询sysindexes.crdate来确认索引的创建时间。
select object_name(id),indid,name,crdate from sysindexes
另外修复索引的方法:
	
1、保存索引的创建语法,手动删除索引后再创建索引;
2、reorg rebuild table_name index_name