Home > SQL Server Tips > Database Development > Undocumented stored procedure: Repair table indexes with sp_fixindex
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE DEVELOPMENT

Undocumented stored procedure: Repair table indexes with sp_fixindex


Serdar Yegulalp, Contributor
08.23.2005
Rating: -3.20- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


In its collection of undocumented stored procedures, SQL Server 2000 has a function called sp_fixindex that can be used to repair the index for a given system table. System table indexes are crucial elements of a smooth-running SQL Server, making it necessary for you to be able to easily fix corrupted indexes.

You know you have a corrupt system table index when you get log error 605. Fixing the index with sp_fixindex can save you the hassle of having to restore the database from a backup.

Stored procedure syntax

sp_fixindex <dbname>,<tablename>,<index_id>

dbname is the name of the database to repair, tablename is the name of the system table with the damaged index and index_id is the index ID number for the problem index. If you don't know the index ID number, you can derive it with a quick query:

SELECT NAME, INDID FROM SYSINDEXES WHERE
ID=OBJECT_ID('<tablename>')

Putting the database in single-user mode

You must first put the database in single-user mode before you can run sp_fixindex. One way to do this is with the sp_dboption procedure:

EXEC SP_DPOPTION <database>, SINGLE, TRUE

Taking the database out of single-user mode

To take the database out of single-user mode, use the following procedure:

EXEC SP_DPOPTION <database>, SINGLE, FALSE

You must also run sp_fixindex separately for each index you want to repair. It is possible to run sp_fixindex against the system catalogs, but you must stop and restart the SQL Server service after you do this.

Always run DBCC CHECKDB and CHECKALLOC statements against the repaired database after running sp_fixindex.

About the author: Serdar Yegulalp is editor of the Windows Power Users Newsletter. Check it out for the latest advice and musings on the world of Windows network administrators -- and please share your thoughts as well!


More information from SearchSQLServer.com

  • Tip: Undocumented stored procedure: View SQL Server 2000 raw data
  • Tips: Check out our complete collection of stored procedures
  • Downloads: To access free Windows IT software downloads related to SQL Server visit our Download Library


  • Rate this Tip
    To rate tips, you must be a member of SearchSQLServer.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



    RELATED CONTENT
    Database Development
    Using DELETE and TRUNCATE TABLE statements to delete data in SQL Server
    Speed up reports in SQL Server Reporting Services with caching
    Data Transformation Services vs. SSIS: The key differences
    Working with IntelliSense in SQL Server 2008 Management Studio
    Top tips and tricks for SQL Server database development
    Managing the development lifecycle with Visual Studio Team System 2008
    Processing XML files with SQL Server functions
    A first look at Visual Studio Team System 2008 Database Edition
    How to create a SQL inner join and outer join: Basics to get started
    New datetime data types in SQL Server 2008 offer flexibility

    SQL/Transact SQL (T-SQL)
    Using DELETE and TRUNCATE TABLE statements to delete data in SQL Server
    SQL language crash course (just enough to be dangerous)
    Working with IntelliSense in SQL Server 2008 Management Studio
    SQL Server Mailbag: Stored procedures, triggers and SSRS reports
    Working with sparse columns in SQL Server 2008
    Determining the source of full transaction logs in SQL Server
    New GROUP BY option provides better data control in SQL Server 2008
    Using the OPENROWSET function in SQL Server
    Loading data files with SQL Server's BULK INSERT statement
    Importing and exporting bulk data with SQL Server's bcp utility
    SQL/Transact SQL (T-SQL) Research

    SQL Server Stored Procedures
    SQL Server Mailbag: CALs, witnesses and unwanted changes
    SQL Server Mailbag: Stored procedures, triggers and SSRS reports
    Top tips and tricks for SQL Server database development
    Top 10 SQL Server development tips of 2008
    SQL Server trigger vs. stored procedure to receive data notification
    SQL Server errors, failures and other problems fixed from the trenches
    SQL Server and data manipulation in T-SQL
    How to use SQL Server 2008 hierarchyid data type
    SQL Server stored procedures tutorial: Write, tune and get examples
    Check SQL Server database and log file size with this stored procedure

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    ACID  (SearchSQLServer.com)
    Collaboration Data Objects  (SearchSQLServer.com)
    commit  (SearchSQLServer.com)
    container  (SearchSQLServer.com)
    DAO  (SearchSQLServer.com)
    fetch  (SearchSQLServer.com)
    OLE DB  (SearchSQLServer.com)
    query  (SearchSQLServer.com)
    SQL  (SearchSQLServer.com)
    T-SQL  (SearchSQLServer.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



    SQL Server Development - .NET, C#, T-SQL, Visual Basic
    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts