Home Database Mysql Tutorial DBCC CHECKDB用法 手工修复数据库

DBCC CHECKDB用法 手工修复数据库

Jun 07, 2016 pm 03:17 PM
repair fast database usage

快速修复 DBCC CHECKDB ('数据库名', REPAIR_FAST) 重建索引并修复 DBCC CHECKDB ('数据库名', REPAIR_REBUILD) 如果必要允许丢失数据修复 DBCC CHECKDB ('数据库名'', REPAIR_ALLOW_DATA_LOSS) 如果出现错误:未处理修复语句。数据库需处于单用户模式下。

快速修复
DBCC CHECKDB ('数据库名', REPAIR_FAST)     
重建索引并修复
DBCC CHECKDB ('数据库名', REPAIR_REBUILD)
如果必要允许丢失数据修复
DBCC CHECKDB ('数据库名'', REPAIR_ALLOW_DATA_LOSS)

如果出现错误:未处理修复语句。数据库需处于单用户模式下。

可以先启用单用户模式,方法如下执行存储过程:

Use master
go
sp_dboption 数据库名, single, true

--更改成单用户
     alter   database   ams2   set   single_user   with   rollback   immediate  

--还原数据库为多用户模式
   alter database ams2 set multi_user   with rollback immediate

############################################################
############################################################


手工修复数据库试例

操作步骤:

----------------------------------------------------------------------------------------------
   进入SQL查询分析器,执行语句:

   --检查数据库完整性
     dbcc checkdb('ams1')

     执行结果:
---------------------------------------------------------------
     CHECKDB 发现了 0 个分配错误和 11 个一致性错误(在数据库 'ams1' 中)。
repair_allow_data_loss 是最低的修复级别(对于由 DBCC CHECKDB (ams1 ) 发现的错误而言)。
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。 

   说明数据库确实有问题,11个错误,找到错误地方:
-------------------------------------------------------------------------------
   对象 'Tb_Archives_File_1' 有 3777 行,这些行位于 172 页中。
CHECKDB 发现了 0 个分配错误和 2 个一致性错误(在表 'Tb_Archives_File_1' 中,该表的对象 ID 为 907150277)。

     表明 'Tb_Archives_File_1' 表确实有2个错误,难怪一查询就要死机,于是运行语句进行表修复:
--------------------------------------------------------------------------------------
     --以repair_allow_data_loss级别修复表
     dbcc   checktable('Tb_Archives_File_1',repair_allow_data_loss)  
     go  

     执行结果:
     服务器: 消息 7919,级别 16,状态 3,行 2
     未处理修复语句。数据库需要处于单用户模式下。
     DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。 
   --------------------------------------------------------------------------------------------------- 
     需要将数据库改为"单用户模式",于是再执行:
     --更改成单用户
     alter   database   ams2   set   single_user   with   rollback   immediate  
go  
     --已repair_allow_data_loss级别修复表
     dbcc   checktable('Tb_Archives_File_1',repair_allow_data_loss)  
go  


     --若还有问题,修复索引表
   DBCC   DBREINDEX('Tb_Archives_File_1')  

   --再修复表
   DBCC   CHECKTABLE('Tb_Archives_File_1')  

   直到返回的结果没有错误!

   --查询是否正常
   select * from Tb_Archives_File_1

   再查询那张错误表,不报错,也不死机了,数据也完好无损.....哈哈....

   --还原数据库为多用户模式
   alter database ams2 set multi_user   with rollback immediate

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

iPhone stuck in airplane mode: How to fix it iPhone stuck in airplane mode: How to fix it Jun 15, 2024 pm 02:16 PM

Airplane mode is very convenient in some situations. However, the same airplane mode may give you a headache if your iPhone suddenly gets stuck on it. In this article, we have designed this set of solutions to get your iPhone out of airplane mode. Quick fix – 1. Try disabling Airplane Mode directly from Control Center. 2. If you are unable to disable Airplane Mode from Control Center, you can disable Airplane Mode directly from the Settings tab – If these tips don’t work, follow the fixes below to resolve the issue. Fix 1 – Force Restart Your Device The process of force restarting your device is very simple. All you have to do is follow these step-by-step instructions. Step 1 – You can start the process by pressing and releasing the Volume Up button. step

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

See all articles