Common SQL server data repair commands DBCC

Source: Internet
Author: User
Ms SQL Server provides many database repair commands that can be attempted when the database challenges or some cannot complete the read. 1. After DBCC checkdb restarts the server and does not perform any operations, run the following SQL statement in the SQL query analyzer to fix Database Consistency errors and allocation errors. Use masterdeclare @ databasename varchar (255) set @ databasename = 'name of the database entity to be repaired 'exec sp_dboption @ databasename, n' single ', N 'true' -- set the target database to DBCC checkdb (@ databasename, repair_allow_data_loss) DBCC checkdb (@ databasename, repair_rebuild) exec sp_dboption @ databasename, N 'single ', N 'false' -- set the target database to a multi-user State and run DBCC checkdb ('name of the database entity to be repaired ') to check whether the database still has errors. Note: Some data may be lost after repair. 2. DBCC checktable if DBCC checkdb check still has an error, you can use DBCC checktable to fix it. Use the name of the database entity to be repaired: declare @ dbname varchar (255) set @ dbname = 'name of the database entity to be repaired: 'exec sp_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) ------ change 'name of the data table to be repaired name' to the name of the data table that encountered an error when running DBCC checkdb exec sp_dboption @ dbname, 'single user', 'false' 3. other commonly used repair commands DBCC dbreindex to reconstruct one or more indexes of a specified database table usage: DBCC dbreindex (Table Name, '') repairs all indexes of this table. There are also many other repair commands, such as DBCC checkident, which have a low probability of use. You can search for them in ms SQL Server online series.
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.