重建表索引的语句(SQL数据库所有百威软件通用)

2019-03-04 21:44:45

此语句只要粘到查询分析器,选择要对哪个帐套重建表索引,执行就可以了

 declare @table_id varchar(100) ,
  @sql  nvarchar(500)
 declare get_table cursor for
  select name from sysobjects where xtype = 'U' and name not in ('dtproperties', 'pbcatcol',
   'pbcatedt', 'pbcatfmt', 'pbcattbl', 'pbcatvld','坏表1','坏表2','坏表3...')  order by name
 open get_table
 fetch get_table into @table_id
 while @@fetch_status = 0
 begin
   print '正在处理表:'+@table_id
  select @sql = 'DBCC DBREINDEX (' + @table_id + ', ' + char(39) + char(39) + ')'
  execute sp_executesql @sql
  fetch get_table into @table_id
 end
 deallocate get_table