茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1670289 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_00037.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

DB研討會 : [轉貼]SQLSERVER數據庫置疑、可疑、脫機、單用戶、緊急模式等的修復

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]SQLSERVER數據庫置疑、可疑、脫機、單用戶、緊急模式等的修復

SQLSERVER數據庫置疑、可疑、脫機、單用戶、緊急模式等的修復

(2013-08-28 15:06:47)

    數據庫出現置疑、可疑、脫機、單用戶、緊急模式主要是因為數據庫的日誌文件除了問題,2000和2008修復方式不一樣,2008的修復腳本在2000中不適用,主要是不被2000識別。

   假設數據庫名為:eisdoc:

   sqlserver2000數據庫置疑的處理方式:

1.設置數據庫允許直接操作系統表

此操作可以在SQL Server Enterprise Manager裡面選擇數據庫服務器,按右鍵,選擇「屬性」,在「服務器設置」頁面中將「允許對系統目錄直接修改」一項選中。

2.設置eisdoc為緊急修復模式
update sysdatabases set status=-32768 where dbid=DB_ID('eisdoc')
關閉打開企業管理器,此時可以在SQL Server Enterprise Manager裡面看到該數據庫處於「只讀\置疑\脫機\緊急模式」可以看到數據庫裡面的表,但是僅僅有系統表
3.重建數據庫日誌文件

dbcc rebuild_log('eisdoc','E:\Microsoft SQL Server\Data\eisdoc_log.ldf')
執行過程中,如果遇到下列提示信息:
服務器: 消息 5030,級別 16,狀態 1,行 1
未能排它地鎖定數據庫以執行該操作。
DBCC 執行完畢。如果 DBCC 輸出了錯誤信息,請與系統管理員聯繫。
說明您的其他程序正在使用該數據庫,如果剛才您在F步驟中使用SQL Server Enterprise Manager打開了eisdoc庫的系統表,那麼退出SQL Server Enterprise Manager就可以了。(關閉企業管理器,如果別的機器從網絡訪問數據庫,也把網絡關閉)
正確執行完成的提示應該類似於:
警告: 數據庫 'eisdoc' 的日誌已重建。已失去事務的一致性。應運行 DBCC CHECKDB 以驗證物理一致性。將必須重置數據庫選項,並且可能需要刪除多餘的日誌文件。
DBCC 執行完畢。如果 DBCC 輸出了錯誤信息,請與系統管理員聯繫。
此時打開在SQL Server Enterprise Manager裡面會看到數據庫的狀態為「只供DBO使用」。此時可以訪問數據庫裡面的用戶表了。
4.驗證數據庫一致性(可省略)
dbcc checkdb('iBusinessWork')
一般執行結果如下:
CHECKDB 發現了 0 個分配錯誤和 0 個一致性錯誤(在數據庫 'eisdoc' 中)。
DBCC 執行完畢。如果 DBCC 輸出了錯誤信息,請與系統管理員聯繫。
5.設置數據庫為正常狀態
sp_dboption 'eisdoc','dbo use only','false'
如果沒有出錯,那麼現在就可以正常的使用恢復後的數據庫啦。
6.關閉「允許對系統目錄直接修改」一項。


因為平時直接操作系統表是一件比較危險的事情。當然,我們可以在SQL Server Enterprise Manager裡面恢復。

 

    sqlserver2008數據庫可疑文件的修復方式:

1.設置數據庫狀態,腳本:EXEC sp_resetstatus 'eisdoc'

2.設置數據庫為緊急模式,腳本:ALTER DATABASE eisdoc SET EMERGENCY

3.設置數據庫為單用戶模式(對數據庫檢查修復只能在單用戶模式下),腳本:ALTER DATABASE eisdoc SET SINGLE_USER

4.檢查並修復數據庫,會提示你修復數據庫可能丟失數據,正常應該不會丟失數據庫數據,但是數據庫日誌的完整性將受到破壞,腳本:DBCC CheckDB (eisdoc, REPAIR_ALLOW_DATA_LOSS)

5.恢復數據庫為多用戶模式,腳本:ALTER DATABASE eisdoc SET MULTI_USER

以上五步即可修復sqlserver2008中的可疑文件


原文出處:SQLSERVER数据库置疑、可疑、脱机、单用户、紧急模式等的修复_女施主请留步_新浪博客
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]數據庫為什麼不能脫機,點了脫機就這樣一直拖著
數據庫為什麼不能脫機,點了脫機就這樣一直拖著....!點了下面的關閉,數據庫就不正常了出現各種疑難雜症

sqlserver脫機過程中先要將提交的操作commit後才執行,很可能是之前的sql操作鎖住了表或數據,所以數據庫就一直在等待解鎖了,這種情況檢查一下數據庫應用有無吊住線程

追問
您回答還是比較專業的!我現在點脫機後一直這樣脫機,我關閉了,然後又一次點的脫機,脫機成功了,然後也聯機亮了也聯機上了!
但有時候第二次脫機還是報錯,刪除數據庫和分離數據庫都報錯 !還會自動變成數據庫(單個用戶)這時候什麼操作都不能做了!不過還是把數據庫分離掉了!具體怎麼分離掉的記不得了!
那以後脫機之前要做什麼才能保證脫機失誤減少?你說的鎖住了表和數據庫是怎麼回事?
追答
可以有個簡單的辦法測試一下是數據庫問題還是應用程序問題 就是關閉所有和數據庫相關的應用程序 然後重啟數據庫後再嘗試脫機操作 如果能正常脫機說明之前的問題是應用導致的 如果仍然有上述問題 那可能是數據庫本身問題了 建議官網升級

脫機失敗的原因:
1、數據損壞,可以通過 dbcc checkdb('NG0001') 命令檢查數據是否有問題,如有問題請在網上查找相關的解決方案修復數據庫。
2、當前數據庫還有用戶在使用,可以在「活動監視器」裡檢查有無「NG0001」的連接,如有,需要將該連接終止才能繼續脫機。(有些是自動連接的,可以多刷新幾次,確認沒連著了再脫機)

有程序正在訪問數據庫,或者數據庫文件本身存在錯誤,就會出現這樣的情況
檢查是否有數據庫訪問,如果有關閉程序
如果還是不行就強行關閉數據庫服務,然後用單機模式檢查修復數據庫錯誤,如果這樣都不行說明數據庫文件錯誤比較嚴重了,建議恢復備份

原文出處:数据库为什么不能脱机,点了脱机就这样一直拖着....!点了下面的关闭,数据库就不正常了出现各种疑难杂症_百度知道
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]嘗試數據庫被標記為RESTORING的處理方式

嘗試數據庫被標記為RESTORING的處理方式

嘗試數據庫被標記為RESTORING的處理方式

/****

by select left('claro',2),in 西安 ,2009-03-27 00:29:23.450

Microsoft SQL Server 2005 - 9.00.1406.00

(Intel X86)

Mar 3 2007 18:40:02

Copyright (c) 1988-2005 Microsoft Corporation

Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

****/

USE [master]

GO

-->1. 查詢數據庫狀態

select state_desc , name ,user_access_desc from sys.databases where name = 'db'

--state_desc name user_access_desc


--RESTORING Db MULTI_USER

-->2. 修改數據庫狀態

ALTER DATABASE [Db] SET ONLINE

-- 消息 5052 ,級別 16 ,狀態 1 ,第 1

-- 當數據庫處於 Restoring 狀態時,不允許 ALTER DATABASE

-- 消息 5069 ,級別 16 ,狀態 1 ,第 1

--ALTER DATABASE 語句失敗。

-->3. 設置數據庫狀態為緊急恢復模式

ALTER DATABASE [Db] SET EMERGENCY

-- 消息 5052 ,級別
16 ,狀態 1 ,第 1

-- 當數據庫處於 Restoring 狀態時,不允許 ALTER DATABASE

-- 消息 5069 ,級別 16 ,狀態 1 ,第 1

--ALTER DATABASE 語句失敗。

-->4. 設置數據庫狀態為單用戶模式

ALTER DATABASE [Db] SET SINGLE_USER

-- 消息 5052 ,級別 16 ,狀態 1 ,第 1

-- 當數據庫處於 Restoring 狀態時,不允許 ALTER DATABASE

-- 消息
5069 ,級別 16 ,狀態 1 ,第 1

--ALTER DATABASE 語句失敗。

-->5.CHECKDB 檢查

DBCC CHECKDB (db ,REPAIR_ALLOW_DATA_LOSS )

-- 消息 927 ,級別 14 ,狀態 2 ,第 1

-- 無法打開數據庫 'Db' 。該數據庫正在進行還原。

-->6. 嘗試用備份集繼續還原

RESTORE DATABASE [Db] FROM DISK = N 'c:/db.bak' WITH FILE = 1 , NOUNLOAD , REPLACE ,
STATS = 10

GO

-- 已處理百分之 13

-- 已處理百分之 22

-- 已處理百分之 31

-- 已處理百分之 40

-- 已處理百分之 54

-- 已處理百分之 63

-- 已處理百分之 72

-- 已處理百分之 81

-- 已處理百分之 90

-- 已處理百分之 100

-- 已為數據庫 'Db' ,文件 'Db' ( 位於文件 1 )
處理了 176 頁。

-- 已為數據庫 'Db' ,文件 'Db_log' ( 位於文件 1 ) 處理了 2 頁。

--RESTORE DATABASE 成功處理了 178 頁,花費 0.159 (9.125 MB/ )

-->7. 檢查數據庫狀態

select state_desc , name ,user_access_desc from sys.databases where name = 'db'

--state_desc name user_access_desc

--ONLINE Db MULTI_USER

-- 至此 db
數據庫正常。後續將嘗試數據庫處於置疑等狀態時,數據庫的修復方式。


原文出處:尝试数据库被标记为RESTORING的处理方式 - CSDN博客
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]數據庫一直顯示為正在還原(restoring)狀態--處理

數據庫一直顯示為正在還原(restoring)狀態--處理

備份一數據庫:完整備份、差異備份、事務日誌備份--測試
進行還原時,提示還原成功,可是數據庫一直顯示為正在還原(restoring)狀態。
可以從通過「select * from sysdatabases」查到數據庫名,但是無法操作。


若確認還原完畢,可以用以下代碼解決:


restore database YourDB with recovery
--切換至正常狀態

--RESTORE DATABASE 成功處理了 0 頁,花費 1.337 秒(0.000 MB/秒)。
 --至此可以成功查詢數據!------------------------------------------------------------------或者還原時選擇第一項即可使數據還原結束後處於正常可用狀態!即在界面--  默認行為是: 回滾未提交的事務,使數據庫處於可以使用的狀態。無法還原其他 事務日誌。(RESTORE WITH RECOVERY) 

原文出處: 数据库一直显示为正在还原(restoring)状态--处理 - CSDN博客
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]完整的資料庫還原 (完整復原模式)

完整的資料庫還原 (完整復原模式) Complete Database Restores (Full Recovery Model)

在完整資料庫還原中,目標是還原整個資料庫。 In a complete database restore, the goal is to restore the whole database. 在還原期間,整個資料庫為離線狀態。 The whole database is offline for the duration of the restore. 在讓資料庫的任何部分上線之前,所有的資料都必須復原到一致的位置;此時資料庫的所有部分都會回到相同的時間點,而且沒有未認可的交易存在。 Before any part of the database can come online, all data is recovered to a consistent point in which all parts of the database are at the same point in time and no uncommitted transactions exist.

在完整復原模式下,還原一個或多個資料備份之後,您必須先還原所有後續的交易記錄備份,然後再復原資料庫。
Under the full recovery model, after you restore your data backup or backups, you must restore all subsequent transaction log backups and then recover the database.
您可以將資料庫還原到其中一個記錄備份內的特定 「復原點」 (Recovery point)。 You can restore a database to a specific recovery point within one of these log backups. 復原點可以是特定日期和時間、標示的交易或記錄序號 (LSN)。 The recovery point can be a specific date and time, a marked transaction, or a log sequence number (LSN).

還原資料庫時 (特別是在完整復原模式或大量記錄復原模式下),應該使用單一還原順序。 When restoring a database, particularly under the full recovery model or bulk-logged recovery model, you should use a single restore sequence. 「還原順序」 (Restore sequence) 包含一個或多個還原作業,會在一個或多個還原階段中移動資料。 A restore sequence
consists of one or more restore operations that move data through one or more of the phases of restore.

重要

建議您不要附加或還原來源不明或來源不受信任的資料庫。 We recommend that you do not attach or restore databases from unknown or untrusted sources. 這些資料庫可能包含惡意程式碼,因此可能執行非預期的 Transact-SQL Transact-SQL 程式碼,或是修改結構描述或實體資料庫結構而造成錯誤。 These databases could contain malicious code that might execute unintended Transact-SQL Transact-SQL code or cause errors by modifying the schema or the physical database structure. 使用來源不明或來源不受信任的資料庫之前,請先在非實際執行伺服器的資料庫上執行
DBCC CHECKDB ,同時檢查資料庫中的程式碼,例如預存程序或其他使用者定義程式碼。
Before you use a database from an unknown or untrusted source, run DBCC CHECKDB on the database on a nonproduction server and also examine the code, such as stored procedures or other user-defined code, in the database.

本主題內容: In this Topic:

注意

如需舊版 [SQL Server] SQL Server之備份支援的資訊,請參閱
RESTORE (Transact-SQL)的<相容性支援>一節。
For information about support for backups from earlier versions of [SQL Server] SQL Server, see the "Compatibility Support" section of RESTORE (Transact-SQL).

將資料庫還原到失敗點 Restoring a Database to the Point of Failure

一般而言,將資料庫復原至失敗點的作業,包含下列基本步驟:
Typically, recovering a database to the point of failure involves the following basic steps:

  1. 備份使用中的交易記錄檔 (即所謂的記錄檔結尾)。 Back up the active transaction log (known as the tail of the log). 這會建立結尾記錄備份。 This creates a tail-log backup. 如果沒有使用中的交易記錄,就會遺失該部分記錄中的所有交易。 If the active transaction log is unavailable, all transactions in that part of the log are lost.

    重要

    在大量記錄復原模式下,備份包含大量記錄作業的記錄時,需要存取資料庫中的所有資料檔案。 Under the bulk-logged recovery model, backing up any log that contains bulk-logged operations requires access to all data files in the database. 如果無法存取資料檔案,就無法備份交易記錄。 If the data files cannot be accessed, the transaction log cannot be backed up.
    在這種情況下,您必須手動重做最近一次備份記錄之後進行的所有變更。 In that case, you have to manually redo all changes that were made since the most recent log backup.

    如需詳細資訊,請參閱 結尾記錄備份 (SQL Server) For more information, see Tail-Log Backups (SQL Server).

  2. 還原最新的完整資料庫備份,但不復原資料庫 (RESTORE DATABASE database_name FROM backup_device WITH NORECOVERY)。 Restore the most recent full database backup without recovering the database (RESTORE DATABASE database_name
    FROM backup_device WITH NORECOVERY).

  3. 如果有差異備份存在,請還原最新的備份,但是不要復原資料庫 (RESTORE DATABASE database_name FROM differential_backup_device WITH NORECOVERY)。 If differential backups exist, restore the most recent one without recovering the database (RESTORE DATABASE database_name FROM differential_backup_device WITH NORECOVERY).

    還原最近一次的差異備份,可減少必須還原的記錄備份數目。 Restoring the most recent differential backup reduces the number of log backups that must be restored.

  4. 從剛才還原的備份之後所建立的第一個交易記錄備份開始,依順序以 NORECOVERY 還原記錄。 Starting with the first transaction log backup that was created after the backup you just restored, restore the logs in sequence with NORECOVERY.

  5. 復原資料庫 (RESTORE DATABASE database_name
    WITH RECOVERY)。
    Recover the database (RESTORE DATABASE database_name WITH RECOVERY). 或者,這個步驟也可以合併在還原最後的記錄備份。 Alternatively, this step can be combined with restoring the last log backup.

    下圖顯示此還原順序。 The following illustration shows this restore sequence. 在失敗發生之後 (1),會建立結尾記錄備份 (2)。 After a failure occurs (1), a tail-log backup is created (2). 接下來,資料庫會還原至失敗點。 Next, the database is restored to the point of the failure. 這個程序牽涉到還原資料庫備份、後續的差異備份,以及在差異備份之後所進行的每一個記錄備份,包括結尾記錄備份在內。 This involves restoring a database backup, a subsequent differential backup, and every log backup taken after the differential backup, including the tail-log backup.


    完成資料庫還原至失敗的時間 Complete database restore to the time of a failure

注意

當您將資料庫備份還原至不同的伺服器執行個體時,請參閱 使用備份與還原複製資料庫 When you restore a database backup onto a different server instance, see
Copy Databases with Backup and Restore.

基本 Transact-SQL RESTORE 語法 Basic Transact-SQL RESTORE Syntax

上圖中還原順序的基本 RESTORE Transact-SQL Transact-SQL 語法如下: The basic RESTORE
Transact-SQL Transact-SQL syntax for the restore sequence in the preceding illustration is as follows:

  1. RESTORE DATABASE <database> FROM full database backup WITH NORECOVERY; RESTORE DATABASE database FROM full database backup WITH NORECOVERY;

  2. RESTORE DATABASE database FROM full_differential_backup WITH NORECOVERY; RESTORE DATABASE database FROM full_differential_backup WITH NORECOVERY;

  3. RESTORE LOG database FROM log_backup WITH NORECOVERY; RESTORE LOG database FROM log_backup WITH NORECOVERY;

    針對其他每個記錄備份重複此還原記錄步驟。
    Repeat this restore-log step for each additional log backup.

  4. RESTORE DATABASE <database> WITH RECOVERY; RESTORE DATABASE database WITH RECOVERY;

範例:復原到失敗點 (Transact-SQL) Example: Recovering to the Point of Failure (Transact-SQL)

下列 Transact-SQL Transact-SQL 範例顯示將資料庫還原到失敗點之還原順序中的基本選項。 The following Transact-SQL Transact-SQL example shows the essential options in a restore sequence that restores the database to the point of failure. 此範例會建立資料庫的結尾記錄備份。 The example creates a tail-log backup of the database. 接下來,此範例會還原完整的資料庫備份和記錄備份,然後還原結尾記錄備份。
Next, the example restores a full database backup and log backup and then restores the tail-log backup. 此範例會在一個不同的最後步驟中復原資料庫。 The example recovers the database in a separate, final step.

注意

此範例使用 完整資料庫備份 (SQL Server)的<相容性支援>一節。 This example uses a database backup and log backup that is created in the "Using Database Backups Under the Full Recovery Model" section in Full Database Backups (SQL Server). 在資料庫備份之前,
AdventureWorks2012 AdventureWorks2012 範例資料庫會設定為使用完整復原模式。
Before the database backup, the AdventureWorks2012 AdventureWorks2012 sample database was set to use the full recovery model.


USE master;
--Create tail-log backup.
BACKUP LOG AdventureWorks2012
TO DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH NORECOVERY;
GO
--Restore the full database backup (from backup set 1).
RESTORE DATABASE AdventureWorks2012
FROM DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH FILE=1,
NORECOVERY;
--Restore the regular log backup (from backup set 2).
RESTORE LOG AdventureWorks2012
FROM DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH FILE=2,
NORECOVERY;
--Restore the tail-log backup (from backup set 3).
RESTORE LOG AdventureWorks2012
FROM DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH FILE=3,
NORECOVERY;
GO
--recover the database:
RESTORE DATABASE AdventureWorks2012 WITH RECOVERY;
GO

將資料庫還原到記錄備份內的時間點 Restoring a Database to a Point Within a Log Backup

在完整復原模式下,完整資料庫還原通常可以復原到某個時間點、標示的交易或記錄備份內的 LSN。 Under the full recovery model, a complete database restore can usually be recovered to a point of time, a marked transaction, or an LSN within a log backup. 然而,在大量記錄復原模式下,如果記錄備份包含大量記錄的變更,則無法進行時間點復原。 However, under the bulk-logged recovery model, if the log backup contains bulk-logged changes, point-in-time recovery is not possible.

範例時間點還原案例 Sample Point-in-Time Restore Scenarios

下列範例假設有一個關鍵任務的資料庫系統,每天午夜時會建立一次完整資料庫備份,從星期一到星期六每小時整點時會建立一次差異資料庫備份,而全天每隔 10 分鐘會建立一次交易記錄備份。
The following example assumes a mission-critical database system for which a full database backup is created daily at midnight, a differential database backup is created on the hour, Monday through Saturday, and transaction log backups are created every 10 minutes throughout the day.
若要將資料庫還原至星期三 5:19 A.M. 時的狀態, To restore the database to the state is was in at 5:19 A.M. 請執行下列工作: Wednesday, do the following:

  1. 還原星期二午夜建立的完整資料庫備份。 Restore the full database backup that was created Tuesday at midnight.

  2. 還原星期三上午 5:00 建立的差異資料庫備份 Restore the differential database backup that was created at 5:00 A.M. on Wednesday.


  3. 套用星期三上午 5:10 建立的交易記錄備份, Apply the transaction log backup that was created at 5:10 A.M. on Wednesday.

  4. 套用星期三上午 5:20 建立的交易記錄備份, Apply the transaction log backup that was created 5:20 A.M. 並指定復原程序僅適用於上午 5:19 之前發生的交易。 on Wednesday, specifying that the recovery process applies only to transactions that occurred before 5:19 A.M.

    或者,如果需要將資料庫還原至星期四 3:04 A.M. 時的狀態, Alternatively, if the database needs to be restored to its state at 3:04 A.M. 但是無法使用星期四 3:00 A.M. 時建立的差異資料庫備份, Thursday, but the differential database backup that was created at 3:00 A.M. 則執行下列操作:
    Thursday is unavailable, do the following:

  5. 還原星期三午夜建立的資料庫備份。 Restore the database backup that was created Wednesday at midnight.

  6. 還原星期四上午 2:00 建立的差異資料庫備份 Restore the differential database backup that was created at 2:00 A.M. 建立的交易記錄備份。 on Thursday.

  7. 套用星期四上午 2:10 到 Apply all the transaction log backups created from 2:10 A.M. 變成上午 3:00。 to 3:00 A.M. 建立的交易記錄備份。 on Thursday.

  8. 套用星期四上午 3:10 建立的交易記錄備份, Apply the transaction log backup that was created at 3:10 A.M. 並在上午 3:04 停止復原程序。
    on Thursday, stopping the recovery process at 3:04 A.M.

注意

如需特定時間點還原的範例,請參閱 將 SQL Server 資料庫還原至某個時間點 (完整復原模式)的<相容性支援>一節。 For an example of a point-in-time restore, see Restore a SQL Server Database to a Point in Time (Full Recovery Model).



原文出處:完整的資料庫還原 (完整復原模式) | Microsoft Docs
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[分享]冷日如何在 M$ SQL Server 2016 上將處在還原狀態中超過 24Hr 的資料庫修復
M$ SQL Server 2016 上將處在還原狀態中超過 24Hr 的資料庫修復

這裡整理一下狀況,冷日的狀況是「明明資料庫還很小,還原應該會非常快速,但跑了 24Hr 以上都還卡著正在還原」(與此同時,該資料庫無法連接管理及使用
上述的方法經測,關鍵語句為:
RESTORE DATABASE YourDBName WITH recovery

這句若能順利執行,資料庫的狀態就解鎖了,後續就好處理了喔!

冷日最後的處理方法:
-- 0.使用主管理資料庫
USE [master]
GO
--先查詢一下你資料庫的狀態
SELECT state_desc,name,user_access_desc FROM sys.databases WHERE name='YourDBName'
--先把資料庫還原成 recovery 狀態
RESTORE DATABASE YourDBName WITH recovery

ALTER DATABASE [YourDBName] SET ONLINE

ALTER DATABASE [YourDBName] SET EMERGENCY

ALTER DATABASE [YourDBName] SET SINGLE_USER

DBCC CHECKDB (YourDBName,REPAIR_ALLOW_DATA_LOSS)

RESTORE DATABASE [YourDBName] FROM  DISK = N'YourBackupFile' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10

GO
--最後確認資料庫狀態
SELECT state_desc,name,user_access_desc FROM sys.databases WHERE name='YourDBName'
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|