如何修复处于“Suspect(挂起)”的数据库

来源:互联网 发布:linux 父目录 编辑:程序博客网 时间:2024/06/10 19:35

非常有用, 亲自测试



Sometimes when you connect to your database server, you may find it in suspect mode. Your database server won’t allow you to perform any operation on that database until the database is repaired.

A database can go in suspect mode for many reasons like improper shutdown of the database server, corruption of the database files etc.

To get the exact reason of a database going into suspect mode can be found using the following query,

DBCC CHECKDB (‘YourDBname’) WITH NO_INFOMSGS, ALL_ERRORMSGS

Output of the above query will give the errors in the database.

To repair the database, run the following queries in Query Analyzer,

  1. EXEC sp_resetstatus ‘yourDBname’;
  2. ALTER DATABASE yourDBname SET EMERGENCY
  3. DBCC checkdb(‘yourDBname’)
  4. ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE
  5. DBCC CheckDB (‘yourDBname’, REPAIR_ALLOW_DATA_LOSS)
  6. ALTER DATABASE yourDBname SET MULTI_USER

and you are done. 

You should keep one thing in mind while using the above queries that the repair mode used here , REPAIR_ALLOW_DATA_LOSS, is a one way operation i.e. once the database is repaired all the actions performed by these queries can’t be undone. There is no way to go back to the previous state of the database. So as a precautionary step you should take backup of your database before executing above mentioned queries.


0 0
原创粉丝点击