Recently I encountered an SQL server 2000 file. ldf is damaged, but mdf is still there. So I tried to restore it. I found some methods on the Internet,
Summary
1) back up the original database files (such as test. mdf) to other places in time
2) Stop the server
3) Delete the test. mdf file.
4) re-create a database with the same name as test.
5) Delete the test. ldf file of the newly created test database and overwrite the newly created test. mdf file with the test. mdf file.
6) Start the database server. In this case, the database test status is "Suspect ". At this time, you cannot perform any operations on this database.
. Set the database to allow direct operation of system tables. In SQL Server Enterprise Manager, select the database Server, right-click it, and select "properties". On the "Server Settings" Page, select "allow direct modification to the system directory"
7) set test to the emergency repair mode.
Update sysdatabases set status =-32768 where dbid = DB_ID ('test ')
At this time, you can see in SQL Server Enterprise Manager that the database is in "read-only, suspicious, offline, and emergency mode" to see the tables in the database, but only the system tables
8. Execute the true recovery operation to recreate the database log file.
Dbcc rebuild_log ('test', 'c: \ Program Files \ Microsoft SQL Server \ MSSQL \ Data \ test_log.ldf ')
If the following prompt is displayed during execution:
Server: Message 5030, level 16, status 1, Row 1
The database cannot be locked for this operation.
DBCC execution is complete. If DBCC outputs an error message, contact the system administrator.
This indicates that other programs are using this database. If you opened the system table of the test database using SQL Server Enterprise Manager in step F, you can exit SQL Server Enterprise Manager.
The prompt for correct execution should be similar:
Warning: the log of the database 'test' has been rebuilt. Transaction consistency is lost. Dbcc checkdb should be run to verify physical consistency. The database must be reset and redundant log files may need to be deleted.
DBCC execution is complete. If DBCC outputs an error message, contact the system administrator.
In SQL Server Enterprise Manager, you can see that the database status is "only for DBO ". Now you can access the user tables in the database.
9. Verify Database Consistency
Dbcc checkdb ('test ')
10. Set the database to normal
Sp_dboption 'test', 'dbo use only', 'false'
If no error occurs, Congratulations. Now we can use the recovered database normally.
11. In the last step, we need to restore the "allow direct modification to the system directory" set in Step E.