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 out, and the data is intact.
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 doubts. Ignore it and execute the following statements (note that you must modify the database name)
CopyCode The 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 access the data in the database. In this case, the database itself is generally still faulty. The solution is to use
The database script creates a new database and imports the data.