Database or table repair

Source: Internet
Author: User
MSSqlServer provides many database repair commands. You can try these repair commands when the database is challenged or some cannot complete the reading. 1. After DBCCCHECKDB restarts the server and does not perform any operations, execute the following SQL statement in the SQL query analyzer to fix Database Consistency errors and allocation errors.

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, execute the following SQL statement in the SQL query analyzer to fix Database Consistency errors and allocation errors.

MS SQL Server provides many database repair commands that can be attempted when the database challenges or some cannot complete the read.

1. DBCC CHECKDB
After the server is restarted, if no operation is performed, execute the following SQL statement in the SQL query analyzer to repair the database and fix the consistency and allocation errors of the database.
Then run dbcc checkdb ('name of the database entity to be repaired ') to check whether the database is still faulty. 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.
3. Other common repair commands
Dbcc dbreindex rebuilding one or more indexes of a table in the specified database
Usage: dbcc dbreindex (Table Name, '') fixes all indexes in the table.

<无>
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
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 dbcc checkdb was executed exec sp_dboption @ dbname, 'single user', 'false'
Dbcc dbreindex (Table Name ,'')

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.