DB Reindex
生活随笔
收集整理的這篇文章主要介紹了
DB Reindex
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數據庫在使用一段時間后,就會出現很多的索引碎片。
declare @ID int set @ID=OBJECT_ID('SMT_QC') dbcc showcontig(@ID)Scan Density值越低代表越需做DBCC ReIndex ,剛做完DBCC會等于 ReIndex100%
?
下面是Reindex的存儲
CREATE procedure [dbo].[DBReindex] @DB varchar(20),@RowsLimit int=100000 as set nocount on declare @str varchar(500) create table #tmpTable(TableName varchar(50),rows int,reserved varchar(50),data varchar(50),index_size varchar(50),unused varchar(50)) declare @table as varchar(50)if not exists(select 0 from sysobjects where name='Reindex_Log')CREATE table Reindex_Log(DB varchar(20),RowsLimit int,Tablename varchar(50),TransDatetime datetime)---循?環?將?用?戶?表?insert into #tmptable declare TblCur cursor for select '['+name+']' from sysobjects where xtype='u' open TblCur fetch next from tblcur into @table while @@fetch_status=0 begininsert into #tmptable exec sp_spaceused @tablefetch next from tblcur into @table end close TblCur deallocate TblCur---循?環?Reindex declare TblCur cursor for select '['+TableName+']' from #tmpTable where rows>@RowsLimit open TblCur fetch next from tblcur into @table while @@fetch_status=0 begininsert into reindex_log(db,rowslimit,tablename,transdatetime) values(@DB,@RowsLimit,@table,getdate())dbcc dbreindex(@table)set @str='backup log '+@db+' with no_log'exec(@str)fetch next from tblcur into @table end close TblCur deallocate TblCur ---插?入?日?志? insert into reindex_log(db,rowslimit,tablename,transdatetime) values(@DB,@RowsLimit,'ReindexFinished',getdate()) drop table #tmpTable注意:請不要在當前的Live DB進行Reindex。
轉載于:https://www.cnblogs.com/songguangqin/archive/2009/03/25/1421208.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的DB Reindex的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 孕妇梦到捡金子首饰是什么意思
- 下一篇: 在应用程序级别以外使用注册为 allow