Method 1 (only mdf files without logs can be recovered) proves valid
1. Create a database with the same name.
2. Set the database to offline.
3. Delete the log file (. LDF). The subsequent process is not enough.
4. Log On As a Super User in the query analyzer and execute the following stored procedures. You must Log On As a Super User. This is a system-level stored procedure.
EXEC sp_detach_db @ dbname = 'xxx' // @ dbnam indicates the database to be restored.
EXEC sp_attach_single_file_db @ dbname = 'xxx', @ physname = 'yyyy' // @ physname is the. mdf file path
5. Set the database to online.
6. Refresh the database. The table is displayed and the data is in good condition.
Method 2 (no log file or log file is damaged)
1. Create a database with the same name
2. Stop SQL server again (do not detach the database)
3. overwrite the new database with the data file of the original database.
4. Restart SQL server.
5. When you open the Enterprise Manager, there will be a doubt. Ignore it and execute the following statement (note that you must modify the database name)
Copy codeThe Code is as follows:
Use master
Go
SP_CONFIGURE 'Allow updates', 1 RECONFIGURE WITH OVERRIDE
Go
Update sysdatabases set status = 32768 where name = 'questionable database name''
Go
Sp_dboption 'questionable database name' ', 'single user', 'true'
Go
Dbcc checkdb ('questionable database name '')
Go
Update sysdatabases set status = 28 where name = 'questionable database name''
Go
Sp_configure 'Allow updates', 0 reconfigure with override
Go
Sp_dboption 'questionable database name' ', 'single user', 'false'
Go
6. After completion, You can generally access the data in the database. At this time, the database itself usually needs problems. The solution is to use
The database script creates a new database and imports the data.