Explanation of SQL Server Data Repair command DBCC usage

Source: Internet
Author: User

a severity level of * indicates that data corruption may exist . Possible causes include broken page chains, corrupted IAM, or Invalid entries in the Sys.objects catalog view of the object. These errors are usually caused by hardware or disk device driver failure.

MS SQL Server provides many commands for database repair, which can be attempted when the MS SQL Server database is questioned or if there is no way to complete the read.

1. DBCC CHECKDB

Restarting the server

     UseMasterDeclare @databasename varchar(255)    Set @databasename=' name of the database entity to be repaired 'execsp_dboption@databasenameN Single', N ' true ' – Set the target data base to single-user stateDBCCCheckdb@databasename, Repair_allow_data_loss)DBCCCheckdb@databasename, Repair_rebuild)execsp_dboption@databasenameN Single', N ' false ' – Set the target data base to multi-user state

sql2012 Modifying a single-user state statement for the target database
ALTER DATABASE dt_cms_ojj SET single_user with ROLLBACK IMMEDIATE;
sql2012 Modifying a single-user state statement for the target database
Alter Database Dt_cms_ojj Set Multi_user

Then execute the SQL Server Data Repair command DBCC CHECKDB (' name of the database entity that needs to be repaired ') to check whether the database still has errors. Note: Repair may result in loss of some data.

2. DBCC checktable

If the DBCC CHECKDB check still has errors, you can use DBCC CHECKTABLE to fix them.

 Usethe name of the database entity that needs to be repairedDeclare @dbname varchar(255)Set @dbname=' name of the database entity to be repaired 'execsp_dboption@dbname,’ Single User’,'true ' DBCC CHECKTABLE (' name of the data table to be repaired ', repair_allow_data_loss) DBCC CHECKTABLE (' name of the data table to be repaired ', repair_rebuild)-Put ' The name of the data table that needs to be repaired is changed to execute SQL Server Data Repair command DBCC CHECKDB times the name of the wrong data table exec sp_dboption @dbname, ' Single user ','False
3. Other Common repair commands

DBCC Dbreindex Rebuilding one or more indexes of a table in a specified database

Usage: DBCC dbreindex (table name, ') fixes all indexes on this table.

Explanation of SQL Server Data Repair command DBCC usage

Related Article

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.