zoukankan      html  css  js  c++  java
  • Repair the database using DBCC CHECKDB

    So now if you want to place AdventureWorks2008R2 sample database in a single-user mode, then write the code

    ALTER DATABASE AdventureWorks2008R2 SET SINGLE_USER;
    

      The above code would wait indefinitely if there is a lock on the database or users are connected to the database. So to overcome this situation, use the code below

    ALTER DATABASE AdventureWorks2008R2 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

    If the AUTO_UPDATE_STATISTICS_AYSYNC option for the database is ON, then you will be unable to place the database in single-user mode because the background thread that is used to update the statistics takes a connection against the database.

    • The DBCC offers two repair modes:
      • REPAIR_REBUILD: This performs a repair that does not lead to any data loss.
      • REPAIR_ALLOW_DATA_LOSS: This performs a repair and fixes to the corrupted database structures, and also results in data loss.
    • The following example will let you understand the whole concept, where I have used DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS option;
     ALTER DATABASE AdventureWorks2008R2 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    BEGIN TRANSACTION;
    DBCC CHECKDB ('AdventureWorks2008R2', REPAIR_ALLOW_DATA_LOSS);
    ALTER DATABASE AdventureWorks2008R2 SET MULTI_USER;
    
     

    http://www.sqlservergeeks.com/repair-the-database-using-dbcc-checkdb/

    https://msdn.microsoft.com/en-us/library/ms176064.aspx

  • 相关阅读:
    机器学习问题之屌丝的女神专属
    【读点paper】irgan
    回老园子
    【Linux】常用命令收集
    【Matlab】基本语法
    【Ubuntu】log
    【Java 学习笔记】 Hadoop学习笔记
    【Algorithm】 字符串算法
    【WordPress】小卡的土豆园开张
    【Log】Self-Check Log
  • 原文地址:https://www.cnblogs.com/zangdalei/p/5325911.html
Copyright © 2011-2022 走看看