Restore the. mdf Database

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.