重建表索引的语句(适合所有SQL数据库)
2019-03-04 23:12:55
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
如果没有坏表,执行后的结果: