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

主頁(yè) > 知識(shí)庫(kù) > SQL Server 索引維護(hù)sql語(yǔ)句

SQL Server 索引維護(hù)sql語(yǔ)句

熱門(mén)標(biāo)簽:分享百度地圖標(biāo)注多個(gè)位置 湖南電腦外呼系統(tǒng)平臺(tái) 外呼系統(tǒng)改進(jìn) 廣東防封卡外呼系統(tǒng)原理是什么 地圖標(biāo)注牌 知名電銷(xiāo)機(jī)器人價(jià)格 長(zhǎng)沙智能外呼系統(tǒng) 菏澤語(yǔ)音電銷(xiāo)機(jī)器人加盟公司 電銷(xiāo)機(jī)器人公司 需要哪些牌照
使用以下腳本查看數(shù)據(jù)庫(kù)索引碎片的大小情況:
復(fù)制代碼 代碼如下:

DBCC SHOWCONTIG WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS

以下使用腳本來(lái)處理維護(hù)作業(yè):
復(fù)制代碼 代碼如下:

/*Perform a 'USE database name>' to select the database in which to run the script.*/
-- Declare variables
SET NOCOUNT ON;
DECLARE @tablename varchar(255);
DECLARE @execstr varchar(400);
DECLARE @objectid int;
Declare @IndexName varchar(500);
DECLARE @indexid int;
DECLARE @frag decimal;
DECLARE @maxfrag decimal;
DECLARE @TmpName varchar(500);

-- Declare @TmpName =''
set @TmpName = ''

-- Decide on the maximum fragmentation to allow for.
SELECT @maxfrag = 30.0;

-- Declare a cursor.
DECLARE tables CURSOR FOR
SELECT TABLE_SCHEMA + '.' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';

-- Create the table.
CREATE TABLE #fraglist (
ObjectName char(255),
ObjectId int,
IndexName char(255),
IndexId int,
Lvl int,
CountPages int,
CountRows int,
MinRecSize int,
MaxRecSize int,
AvgRecSize int,
ForRecCount int,
Extents int,
ExtentSwitches int,
AvgFreeBytes int,
AvgPageDensity int,
ScanDensity decimal,
BestCount int,
ActualCount int,
LogicalFrag decimal,
ExtentFrag decimal);

-- Open the cursor.
OPEN tables;

-- Loop through all the tables in the database.
FETCH NEXT
FROM tables
INTO @tablename;

WHILE @@FETCH_STATUS = 0
BEGIN;
-- Do the showcontig of all indexes of the table
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @tablename + ''')
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS');
FETCH NEXT
FROM tables
INTO @tablename;
END;

-- Close and deallocate the cursor.
CLOSE tables;
DEALLOCATE tables;

-- Declare the cursor for the list of indexes to be defragged.
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId,IndexName,IndexId, LogicalFrag
FROM #fraglist
WHERE INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0;

-- Open the cursor.
OPEN indexes;

-- Loop through the indexes.
FETCH NEXT
FROM indexes
INTO @tablename, @objectid, @IndexName,@indexid, @frag;


WHILE @@FETCH_STATUS = 0
BEGIN;
if @frag @maxfrag
Begin
SELECT @execstr = 'ALTER INDEX [' + RTRIM(@IndexName) + '] ON [' + RTRIM(@tablename) + '] REORGANIZE WITH ( LOB_COMPACTION = ON ) '
print @maxfrag + ' ' + @execstr
End
else
Begin
SELECT @execstr = 'ALTER INDEX [' + RTRIM(@IndexName) + '] ON [' + RTRIM(@tablename) + '] REBUILD WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, SORT_IN_TEMPDB = OFF, ONLINE = OFF )'
print @maxfrag + ' ' + @execstr
End

EXEC (@execstr);

--更新統(tǒng)計(jì)信息
IF @TmpName>@tablename
BEGIN
SET @tmpName=@tableName
PRINT 'UPDATE STATISTICS '+@TableName + ' WITH FULLSCAN '
EXEC ('UPDATE STATISTICS '+@TableName + ' WITH FULLSCAN ')
END


FETCH NEXT
FROM indexes
INTO @tablename, @objectid, @IndexName,@indexid, @frag;
END;

-- Close and deallocate the cursor.
CLOSE indexes;
DEALLOCATE indexes;

-- Delete the temporary table.
DROP TABLE #fraglist;
GO

標(biāo)簽:天水 商洛 美容院 呼和浩特 珠海 福建 西寧 泉州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQL Server 索引維護(hù)sql語(yǔ)句》,本文關(guān)鍵詞  SQL,Server,索引,維護(hù),sql,語(yǔ)句,;如發(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)文章
  • 下面列出與本文章《SQL Server 索引維護(hù)sql語(yǔ)句》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于SQL Server 索引維護(hù)sql語(yǔ)句的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 准格尔旗| 巴中市| 安乡县| 阿鲁科尔沁旗| 康定县| 柳林县| 论坛| 安福县| 蕉岭县| 渝北区| 广德县| 明溪县| 化隆| 白银市| 肇州县| 浮山县| 陇川县| 梅州市| 洛川县| 加查县| 哈尔滨市| 手游| 阿拉善左旗| 贵溪市| 临夏市| 丘北县| 荆门市| 玉门市| 天祝| 天气| 勃利县| 克山县| 阜城县| 舞阳县| 五原县| 区。| 原平市| 东乡| 嘉兴市| 陇西县| 天门市|