首页 新闻 搜索 专区 学院

索引碎片如下重建索引,出错,指点是什么原因?

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-12-31 16:36

执行查询“declare @schemaname varchar(255)
declare @tablename varchar(255)
declare @indexname varchar(255)
declare @fragmentation float
declare @command varchar(255)
declare tablecursor cursor for select SCHEMA_NAME(CAST(OBJECTPROPERTYEX(i.object_id,'schemaId')as int)),object_name(i.object_id),i.name,ps.avg_fragmentation_in_percent
from sys.dm_db_index_physical_stats(db_id(),null,null,null,null)as ps join sys.indexes as i on ps.object_id=i.object_id and ps.index_id=i.index_id where avg_fragmentation_in_percent>30
open tablecursor
while @@fetch_status=0
begin
  print @schemaname+'.'+@tablename+'.'+@indexname+'is'+cast(@fragmentation as varchar)+'% fragmentented'
  set @command='alter index '+rtrim(@indexname)+' on['+isnull(@schemaname,'dbo')+'.'+rtrim(@tablename)+'] rebuild'
  exec (@command) 
fetch next from tablecursor into @schemaname,@tablename,@indexname,@fragmentation
end
close tablecursor
deallocate tablecursor”失败,错误如下:“找不到对象 "dbo.MOCMA",因为它不存在或者您没有所需的权限。
dbo.MOCMA表确实存在,而是用SA登录的,不知道为什么,请指点?

herry507的主页 herry507 | 菜鸟二级 | 园豆:241
提问于:2012-10-31 13:47
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册