2011-11-30 14 views
5

मैं उपयोग एसक्यूएल सर्वर 2008 R2, मैं एक डेटाबेसकैसे मेरी डेटाबेस में हर तालिका के लिए सूचकांक को बदलने के लिए

में हर तालिका के लिए सूचकांक के पुनर्निर्माण के लिए इस स्क्रिप्ट का प्रयोग की जरूरत है, मैं एक त्रुटि

USE myDb 
GO 

EXEC sp_MSForEachTable 'ALTER INDEX ALL ON ? REBUILD' 
प्राप्त

त्रुटि:

ALTER INDEX failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.

कोई विचार यह कैसे ठीक करें? धन्यवाद

+0

इस लिंक की जाँच करें: http://www.mssqltips.com/sqlservertip/1367/sql-server-script-to-rebuild-all-indexes-for-all-tables-and - सभी डेटाबेस/यह आपके लिए काम करना चाहिए। –

+1

धन्यवाद शार्क, लेकिन मुझे समझना होगा कि मेरे आदेश में समस्या क्या है। मैं आपके संसाधन धन्यवाद पर विचार रखूंगा! – GibboK

उत्तर

9

एसक्यूएल फूल (मिशेल उफर्ड) के लिए यह करने के लिए एक महान स्क्रिप्ट है - सभी उपयोगकर्ताओं द्वारा किए गए और अच्छी तरह से परीक्षण किया गया।

यह काम का एक बड़ा टुकड़ा है - यह आप विखंडन स्तरों जिसके लिए आप

  • कुछ भी नहीं
  • एक सूचकांक
  • एक सूचकांक कर पुनर्निर्माण

नहीं पुनर्निर्माण को परिभाषित करने की अनुमति देता है पहिया reinvent - just go see and use the script!

+0

आपके संसाधन के लिए धन्यवाद मार्क – GibboK

+0

@marc_s क्या आपको वास्तविक उत्तर सहित दिमाग होगा? मैं लिंक की गई वेबसाइट तक नहीं पहुंच सकता, दुर्भाग्य से यह जवाब लगभग बेकार है क्योंकि यह – Breeze

+0

@Breeze है: क्षमा करें, स्क्रिप्ट 1000 से अधिक लाइन लंबी है - यहां पोस्ट करने के लिए बहुत लंबा है। आप इसे सीधे डाउनलोड यूआरएल के साथ पकड़ने की कोशिश कर सकते हैं: http://sqlfool.com/wp-content/uploads/2011/06/dba_indexDefrag_sp_v41.txt –

1

एक साधारण दृष्टिकोण मैं अपने लिए उपयोग करने का फैसला करता हूं प्रशन। कोड से: http://blog.sqlauthority.com/2009/01/30/sql-server-2008-2005-rebuild-every-index-of-all-tables-of-database-rebuild-index-with-fillfactor/

-- Rebuild eve Index for every Table in the Database. 
    -- Resource: http://blog.sqlauthority.com/2009/01/30/sql-server-2008-2005-rebuild-every-index-of-all-tables-of-database-rebuild-index-with-fillfactor/ 
    USE [YourDbName] 
    GO 

    -- Show Fragmentation sample on YourTable Index. 
    select avg_fragmentation_in_percent, avg_fragment_size_in_pages, fragment_count, avg_page_space_used_in_percent 
    from sys.dm_db_index_physical_stats (DB_ID(), object_id('[dbo].[YourTableName]'), NULL, NULL, 'DETAILED') 

    -- Cursor going over each table and rebuilding every index of database. 
    DECLARE @TableName VARCHAR(255) 
    DECLARE @sql NVARCHAR(500) 
    DECLARE @fillfactor INT 
    SET @fillfactor = 80 
    DECLARE TableCursor CURSOR FOR 
    SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName 
    FROM sys.tables 
    OPEN TableCursor 
    FETCH NEXT FROM TableCursor INTO @TableName 
    WHILE @@FETCH_STATUS = 0 
    BEGIN 
    SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')' 
    EXEC (@sql) 
    FETCH NEXT FROM TableCursor INTO @TableName 
    END 
    CLOSE TableCursor 
    DEALLOCATE TableCursor 
    GO 
संबंधित मुद्दे