SQL Server 2000遺失LDF檔之時, 使用MDF檔復原資料庫

Google到的,真的可以成功復原資料庫。

----------------------------正文開始
----------------------------

Backup .mdf file...
1. Rename database .mdf file .mdf_old
2. Create new database with same name and same mdf and ldf files
3. Stop sql services
4. Rename new db .mdf file to .mdf_new and .ldf file to .ldf_new
5. Rename .mdf_old file to .mdf...
6. Restart sql and you db will show up as suspect...
7. Change the database context to Master and allow updates to system
tables:

Use Master
Go
sp_configure 'allow updates', 1
reconfigure with override
Go

8. Set the database in Emergency (bypass recovery) mode:

-- note the value of the status column for later use
select * from sysdatabases where name = ''
begin tran
update sysdatabases set status = 32768 where name = ''
-- Verify one row is updated before committing
commit tran

If you run DBCC REBUILD_LOG without setting the database in Emergency
mode, the command does not work. You do not receive an error, but the
log is not rebuilt either.

9. Stop and restart SQL server.

If you run DBCC REBUILD_LOG without recycling the server, the following
message displays:

Server: Msg 5023, Level 16, State 2, Line 1 Database must be put in
bypass recovery mode to rebuild the log. DBCC execution completed. If
DBCC printed error messages, contact your system administrator.

10. The syntax for DBCC REBUILD_LOG is as follows:

DBCC REBUILD_LOG('','')

where is the name of the database and is the
physical path to the new log file, not a logical file name. If you do
not specify the full path, the new log is created in the Windows NT
system root directory (by default, this is the Winnt\System32
directory).

11. Rebuild the log with this code:

DBCC TRACEON (3604)
DBCC REBUILD_LOG('','')
Go

If the command is successful, the following message appears:

Warning: The log for database '' has been rebuilt.
Transactional consistency has been lost. DBCC CHECKDB should be run to
validate physical consistency. Database options will have to be reset,
and extra log files may need to be deleted.

After the log is successfully rebuilt, the database is placed in DBO Use
Only mode. That is, the status of the database is 2048 irrespective of
what the status was previously. You must reset the status using
sp_dboption or through the SEM.

12. Set the database in single-user mode and run DBCC CHECKDB to validate
physical consistency:

sp_dboption '', 'single user', 'true'
DBCC CHECKDB('')
Go
begin tran
update sysdatabases set status = where name =
''
-- verify one row is updated before committing
commit tran
Go

13. Turn off the updates to system tables by using:

sp_configure 'allow updates', 0
reconfigure with override
Go

WARNING: After verifying the consistency of the database by running DBCC
CHECKDB, and fixing any errors, please make sure to check the database
for logical consistency as well. Because a new log has been built, the
transactions in the
old log are lost, hence you must also verify the logical consistency of
the data as well.

After you successfully complete the preceding steps, you may use the
database as normal.


MohammedU

留言

匿名表示…
網誌管理員已經移除這則留言。
Alex寫道…
Yesterday I was in unpleasant difficult situation. All my sql .mdf files were corrupted. And I used the the Google and saw there - best .mdf file repair utility. The utility solved my problem for seconds and free of charge as I bore in mind.

熱門文章