婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > SQL2005重新生成索引的的存儲(chǔ)過(guò)程 sp_rebuild_index 原創(chuàng)

SQL2005重新生成索引的的存儲(chǔ)過(guò)程 sp_rebuild_index 原創(chuàng)

熱門(mén)標(biāo)簽:海南自動(dòng)外呼系統(tǒng)價(jià)格 電銷(xiāo)機(jī)器人虛擬號(hào)碼 松原導(dǎo)航地圖標(biāo)注 浙江地圖標(biāo)注 舞鋼市地圖標(biāo)注app 沈陽(yáng)智能外呼系統(tǒng)代理 創(chuàng)業(yè)電銷(xiāo)機(jī)器人 滄州營(yíng)銷(xiāo)外呼系統(tǒng)軟件 九鹿林外呼系統(tǒng)怎么收費(fèi)

公司運(yùn)營(yíng)著的網(wǎng)站,流量很大,網(wǎng)站是交互式的,經(jīng)常在過(guò)了三四個(gè)月的時(shí)候索引生成的碎片就很多,由于很大一部分頁(yè)面沒(méi)有生成靜態(tài),這就導(dǎo)致網(wǎng)站在打開(kāi)的速度上會(huì)變慢。

以前都是手工右擊索引重新生成,但是索引太多,操作起來(lái)費(fèi)時(shí)費(fèi)力,索引在網(wǎng)上找了個(gè)存儲(chǔ)過(guò)程,自己整理了一下,執(zhí)行的時(shí)候只需要選擇相應(yīng)的數(shù)據(jù)庫(kù),運(yùn)行exec sp_rebuild_index即可,如下。

USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[sp_rebuild_index] 
(
  @Rebuild_Fragmentation_Percent smallint = 5  -- 當(dāng)邏輯碎片百分比 > 5% 重新生成索引
)
as
begin
  /* 調(diào)用方法:
  1.針對(duì)當(dāng)前實(shí)例所有數(shù)據(jù)庫(kù):  exec sys.sp_MSforeachdb 'use ?;exec sp_rebuild_index'
  2.針對(duì)當(dāng)前數(shù)據(jù)庫(kù):      exec sp_rebuild_index
  */
  
  --對(duì)系統(tǒng)數(shù)據(jù)庫(kù)不作重新組織索引和重新生成索引
  if (db_name() in ('master','model','msdb','tempdb')) return;  
  
  --如果邏輯碎片(索引中的無(wú)序頁(yè))的百分比 = 5% ,就不作重新組織索引和重新生成索引
  if not exists(select 1 from sys.dm_db_index_physical_stats(db_id(),null,null,null,null) a where a.index_id>0 and a.avg_fragmentation_in_percent > @Rebuild_Fragmentation_Percent) return
  
  
  print replicate('-',60)+char(13)+char(10)+replicate(' ',14)+N'對(duì)數(shù)據(jù)庫(kù) '+quotename(db_name())+N' 進(jìn)行索引優(yōu)化'+replicate(' ',20)+char(13)+char(10)  
    
  declare @sql nvarchar(2000),@str nvarchar(2000)
  
  declare cur_x cursor for 
    select 'alter index '+quotename(a.name)+' on '+quotename(object_schema_name(a.object_id))+'.'+quotename(object_name(a.object_id))+' rebuild;' as [sql]
        ,N'重新生成索引:' +quotename(object_schema_name(a.object_id))+'.'+quotename(object_name(a.object_id))+'.'+quotename(a.name) as [str]
      from sys.indexes a
        inner join sys.dm_db_index_physical_stats(db_id(),null,null,null,null) b on b.object_id=a.object_id
          and b.index_id=a.index_id  
      where a.index_id>0  
        and b.avg_fragmentation_in_percent > @Rebuild_Fragmentation_Percent
      order by object_name(a.object_id),a.index_id
      
  open cur_x
  fetch next from cur_x into @sql,@str  
  
  while (@@fetch_status = 0)
  begin
 print @sql
    exec(@sql)
 
    print @str
    fetch next from cur_x into @sql,@str  
      
  end
  close cur_x
  deallocate cur_x 
    
end

你可能在執(zhí)行過(guò)程中會(huì)遇到如下錯(cuò)誤

消息 195,級(jí)別 15,狀態(tài) 10,過(guò)程 sp_rebuild_index,第 24 行
'object_schema_name' 不是可以識(shí)別的 內(nèi)置函數(shù)名稱(chēng)。

不要擔(dān)心,那是由于沒(méi)有安裝SQL Server SP4補(bǔ)丁造成的,安裝一下補(bǔ)丁即可。

您可能感興趣的文章:
  • mssql 建立索引
  • SQL2000 全文索引完全圖解
  • MSSQL 大量數(shù)據(jù)時(shí),建立索引或添加字段后保存更改提示超時(shí)的解決方法
  • 關(guān)于重新組織和重新生成索引sp_RefreshIndex的介紹
  • SQL2005CLR函數(shù)擴(kuò)展 - 關(guān)于山寨索引
  • MSSQL自動(dòng)重建出現(xiàn)碎片的索引的方法分享
  • 理解Sql Server中的聚集索引
  • Sql Server中的非聚集索引詳細(xì)介
  • 在SQL SERVER中導(dǎo)致索引查找變成索引掃描的問(wèn)題分析
  • 詳解sqlserver查詢(xún)表索引

標(biāo)簽:西藏 商洛 寶雞 公主嶺 臺(tái)灣 咸寧 日喀則 海口

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQL2005重新生成索引的的存儲(chǔ)過(guò)程 sp_rebuild_index 原創(chuàng)》,本文關(guān)鍵詞  SQL2005,重新,生成,索引,的的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《SQL2005重新生成索引的的存儲(chǔ)過(guò)程 sp_rebuild_index 原創(chuàng)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于SQL2005重新生成索引的的存儲(chǔ)過(guò)程 sp_rebuild_index 原創(chuàng)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 西城区| 孟连| 临高县| 囊谦县| 瑞昌市| 临汾市| 格尔木市| 剑阁县| 图木舒克市| 阿巴嘎旗| 葵青区| 永清县| 阳高县| 通道| 金塔县| 万全县| 炉霍县| 南充市| 基隆市| 客服| 惠东县| 连平县| 吉木萨尔县| 长春市| 天水市| 祁连县| 丰宁| 沙田区| 嵊泗县| 招远市| 当涂县| 加查县| 南和县| 杂多县| 洞头县| 中西区| 曲沃县| 柳河县| 仁化县| 虹口区| 和龙市|