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 ,'')