Repair damaged SQL databases such as power outages

Source: Internet
Author: User
Fix the damaged SQL database, such as power failure. For whatever reason, you can test it and try it.

Fix the damaged SQL database, such as power failure. For whatever reason, you can test it and try it.

For example, the database name is FreeHost.
First, set it to single-user mode, then fix it, and then restore the multi-user mode.
Alter database [FreeHost] SET SINGLE_USER
GO
Dbcc checkdb ('freehost', repair_allow_data_loss) WITH TABLOCK
GO
Alter database [FreeHost] SET MULTI_USER
GO


-- CHECKDB has three parameters:
-- REPAIR_ALLOW_DATA_LOSS
-- Execute all the repairs completed by REPAIR_REBUILD, including allocating and unassigning rows and pages to correct the allocation errors, structure row or page errors, and deleting corrupted text objects. These fixes may cause some data loss. The repair operation can be completed under the user transaction to allow the user to roll back the changes. If the rollback is fixed, the database will still contain errors and the backup should be restored. If an error fix is missing due to the severity of the severity level provided, it will omit any fix that depends on the fix. After the restoration, back up the database.
-- REPAIR_FAST Performs small and time-consuming repair operations, such as fixing the additional keys in non-clustered indexes. These repairs can be completed quickly without the risk of data loss.
-- REPAIR_REBUILD: execute all the repairs completed by REPAIR_FAST, including repairs that require a long period of time (such as re-indexing ). There is no risk of data loss when performing these repairs.

-- Dbcc checkdb ('freehost') with NO_INFOMSGS, PHYSICAL_ONLY

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.