重建整个数据库的索引(Server2000)

declare @dbname varchar(50)
select @dbname ='WebFZ'

create table #tableT(tn sysname)
insert into #tableT exec ('select name from '+@dbname+'..sysobjects where xtype = '+''''+'U'+'''')
declare tableCrusor cursor for select tn from #tableT
open tableCrusor
declare @table sysname
fetch next from tableCrusor into @table
while @@fetch_status = 0
begin
set @table = @dbname+'.dbo.'+@table
dbcc dbreindex (@table)
fetch next from tableCrusor into @table
end
close tableCrusor
deallocate tableCrusor

原文地址:https://www.cnblogs.com/Thenext/p/10308497.html