SQL Server 2005数据库日志文件损坏的情况下如何恢复数据库
在某些偶然的情況下,會(huì)引起SQL Server 2005數(shù)據(jù)庫(kù)日志文件的損壞,比如:硬件故障、計(jì)算機(jī)非正常重啟或關(guān)機(jī)。
當(dāng)SQL Server 2005數(shù)據(jù)庫(kù)日志文件損壞時(shí),可能會(huì)出現(xiàn)以下情況:
1、在SQL Server Management Studio中顯示數(shù)據(jù)庫(kù)處于置疑(suspect)狀態(tài)。
2、事件日志可能會(huì)出現(xiàn)如下錯(cuò)誤信息:
???Could not redo log record (21737:686:9), for transaction ID (0:2334886), on page (1:37527), database 'Test' (database ID 15). Page: LSN = (21735:299:5), type = 2. Log: OpCode = 3, context 19, PrevPageLSN: (21737:615:1). Restore from a backup of the database, or repair the database.
???During redoing of a logged operation in database 'Test', an error occurred at log record ID (76116:286:2). Typically, the specific failure is previously logged as an error in the Windows Event Log service. Restore the database from a full backup, or repair the database.?
3、無(wú)法分離數(shù)據(jù)庫(kù)
4、用CREATE DATABASE DBName ON ( FILENAME = N'DBFile' ) ?FOR ATTACH_REBUILD_LOG附加數(shù)據(jù)庫(kù)時(shí)出現(xiàn)提示:The log cannot be rebuilt because the database was not cleanly shut down.
恢復(fù)方法:
1、停止數(shù)據(jù)庫(kù)服務(wù)。
2、將需要恢復(fù)的數(shù)據(jù)庫(kù)文件復(fù)制到另外的位置。
3、啟動(dòng)數(shù)據(jù)庫(kù)服務(wù)。
4、確認(rèn)要恢復(fù)的數(shù)據(jù)庫(kù)文件已經(jīng)成功復(fù)制到另外的位置,然后在SQL Server Management Studio中刪除要恢復(fù)的數(shù)據(jù)庫(kù)。
5、新建同名的數(shù)據(jù)庫(kù)(數(shù)據(jù)庫(kù)文件名也要相同)。
6、停止數(shù)據(jù)庫(kù)服務(wù)。
7、用第2步中備份的.mdf文件覆蓋新數(shù)據(jù)庫(kù)的同名文件。
8、啟動(dòng)數(shù)據(jù)庫(kù)服務(wù)。
9、運(yùn)行alter database dbname set emergency,將數(shù)據(jù)庫(kù)設(shè)置為emergency mode
10、運(yùn)行下面的命令就可以恢復(fù)數(shù)據(jù)庫(kù):
declare?@databasename?varchar(255)?
set?@databasename='要恢復(fù)的數(shù)據(jù)庫(kù)名稱'?
exec?sp_dboption?@databasename,?N'single',?N'true'?--將目標(biāo)數(shù)據(jù)庫(kù)置為單用戶狀態(tài)?
dbcc?checkdb(@databasename,REPAIR_ALLOW_DATA_LOSS)?
dbcc?checkdb(@databasename,REPAIR_REBUILD)?
exec?sp_dboption?@databasename,?N'single',?N'false'--將目標(biāo)數(shù)據(jù)庫(kù)置為多用戶狀態(tài)?
上面的方法是通過(guò).mdf文件恢復(fù)數(shù)據(jù)庫(kù),即使log文件丟失也可以恢復(fù)。
總結(jié)
以上是生活随笔為你收集整理的SQL Server 2005数据库日志文件损坏的情况下如何恢复数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 经典句子
- 下一篇: NET 2.0中WinForm自定义的程