DBCC CHECKDB usage Manual Repair Database

Source: Internet
Author: User

Quick fix
DBCC CHECKDB (' database name ', repair_fast)
Rebuild indexes and fix
DBCC CHECKDB (' database name ', Repair_rebuild)
If necessary to allow loss of data repair
DBCC CHECKDB (' database name ', Repair_allow_data_loss) If an error occurred: The repair statement was not processed. The database needs to be in single-user mode. You can first enable single-user mode by executing the stored procedure as follows: Use master
Go
sp_dboption database name, single, true--change to one-user
ALTER DATABASE name set Single_user with rollback immediate-restore database to multi-user mode
ALTER DATABASE name set Multi_user with rollback immediate manual repair of databases sample procedure:--------------------------------------------- -------------------------------------------------
Enter SQL Query Analyzer, EXECUTE statement:--Check Database integrity
DBCC CHECKDB (' database name ') execution result:
---------------------------------------------------------------
CHECKDB found 0 allocation errors and 11 conformance errors (in database ' Ams1 ').
Repair_allow_data_loss is the lowest level of repair (for errors found by DBCC CHECKDB (database name)).
DBCC execution is complete. If DBCC outputs an error message, contact your system administrator.
EXPLANATION The database does have a problem, 11 errors, find the wrong place:-------------------------------------------------------------------------------
The object ' Tb_archives_file_1 ' has 3777 rows, which are located on page 172.
CHECKDB found 0 allocation errors and 2 conformance errors (in table ' Tb_archives_file_1 ', the table has an object ID of 907150277). Indicates that the ' tb_archives_file_1 ' table does have 2 errors, no wonder a query will crash, and then run the statement to fix the table:--------------------------------------------------------- -----------------------------
--fix table at Repair_allow_data_loss level
DBCC CHECKTABLE (' tb_archives_file_1 ', Repair_allow_data_loss)
Go execution Results:
Server: Msg 7919, Level 16, State 3, line 2
The repair statement was not processed. The database needs to be in single-user mode.
DBCC execution is complete.   If DBCC outputs an error message, contact your system administrator. ---------------------------------------------------------------------------------------------------need to change the database to " Single-user mode, and then execute:
--Change into a single user
ALTER DATABASE name set Single_user with rollback immediate
Go
--repair_allow_data_loss level fix table
DBCC CHECKTABLE (' tb_archives_file_1 ', Repair_allow_data_loss)
Go
--if there is still a problem, repair the index Table
DBCC dbreindex (' tb_archives_file_1 ')--repair table
DBCC checktable (' tb_archives_file_1 ') until the returned result is no error! --Query is normal
SELECT * FROM Tb_archives_file_1 again query the error table, no error, no crash, the data is intact ..... Haha ...--Restore the database to multi-user mode
ALTER DATABASE name set Multi_user with rollback immediate turn from: http://blog.csdn.net/zhejingyuan/article/details/11681865

DBCC CHECKDB usage Manual Repair Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.