The SQL restoration method for the master database is only for how to restore the mdf file database, mastermdf

Source: Internet
Author: User
Tags mssqlserver

The SQL restoration method for the master database is only for how to restore the mdf file database, mastermdf

First, let's talk about how SQL Server restores the master database. The specific steps are as follows:

Step 1:CopyModel. mdf, mastlog. ldf, model. mdf, modellog. ldf, msdbdata. mdf, msdblog. ldfFile.
From X: \ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ Binn \ Templates
To X: \ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ DATA
Note:The preceding "X: \ Program Files \ Microsoft SQL Server" is the installation directory of SQL Server. The following "C: \ Program Files \ Microsoft SQL Server" is the directory on the system disk.

Step 2:Locate and execute the installation command
1. First find the installation command: C: \ Program Files \ Microsoft SQL Server \ 100 \ Setup Bootstrap \ Release \ setup.exe
2. Run the command

For Windows Authentication mode, you only need the following syntax:
Copy codeThe Code is as follows: setup/ACTION = REBUILDDATABASE/QUIET/INSTANCENAME = <instance name>/SQLSYSADMINACCOUNTS = <accounts>

For the compound Authentication mode, you must use the/SAPWD parameter to provide the sa password:
Copy codeThe Code is as follows: setup/ACTION = REBUILDDATABASE/QUIET/INSTANCENAME = <instance name>/SQLSYSADMINACCOUNTS = <accounts>/SAPWD = <sa password>

I set the compound Authentication Mode during installation. The SQL Server System Administrator account is in the administrators group, and the sa password is 123456. The default instance is MSSQLSERVER.
Therefore, execute the following command on the command line:
Copy codeCode: setup/ACTION = REBUILDDATABASE/QUIET/INSTANCENAME = MSSQLSERVER/SQLSYSADMINACCOUNTS = administrators/SAPWD = 123456

Step 3:There is no prompt after the execution is completed (whether successful or not), but you can view the Installation Log immediately in C: \ Program Files \ Microsoft SQL Server \ 100 \ Setup Bootstrap \ Log \ Summary.txt.

Finally, the SQL Server service is successfully started in SQL Server Configuration Manager.

What should I do if this problem occurs during the process of restoring the database by SQL?How to restore mdf files,That isHow to restore a database with log files

Follow these steps to restore an SQL database:

1. Create a database with the same name.

2. Stop the Database Service and overwrite the new primary database file (TIPS: You 'd better put it in the same disk, delete or remove the new primary database file, and then cut the primary database file to be restored, this saves time .)

3. Start the Database Service and change the database to a suspicious or suspicious state. Then run the following command in the query Analyzer:
Alter database: database Name set emergency without log files
Set to emergency.

4. Run again:
Alter database: database Name set single_user without log files
Or:
Sp_dboption 'database name without log file', 'single user', 'true'
Set to single-user mode.

5. Check and recreate the log file and run:
Dbcc checkdb ('database name without log file', REPAIR_ALLOW_DATA_LOSS)
This takes a long time. Wait patiently! If an error message is displayed, run the following command:
Dbcc checkdb ('database name without log file', REPAIR_REBUILD)
. If there are no errors, skip this step.

6. Restore to multi-user mode
Alter database: database Name set multi_user without log files
Or:
Sp_dboption 'database name without log file', 'single user', 'false'
Refresh the database and you will see the repaired database.

The above is the SQL database restoration method shared for you. I hope it will help you recover the database.

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.