If the backup database has two files. LDF and. MDF: Open the Enterprise Manager, right-click the instance, select all tasks, and attach the database. MDF file. Alternatively, enter sp_attach_db Database Name, path file name. ldf, and path file name. MDFSQLServer database backup in the query analyzer.
If the backup database has two files. LDF and. MDF: Open the Enterprise Manager, right-click the instance, select all tasks, and attach the database. MDF file. Alternatively, enter sp_attach_db Database Name, path file name. ldf, and path file name. mdf SQL Server database backup in the query analyzer.
If the backup database has two files. LDF and. MDF: Open the Enterprise Manager, right-click the instance, select all tasks, and attach the database. MDF file.
Alternatively, enter:
Sp_attach_db "Database Name", "path file name. ldf", "path file name. MDF"
There are two ways to back up SQL Server databases: one is to back up DATABASE files using BACKUP DATABASE, and the other is to directly copy the DATABASE file mdf and Log File ldf. The following describes the backup and recovery of the latter. This document assumes that you are familiar with SQL Server Enterprise Manager and SQL Server Quwey Analyser)
1. Normal backup and recovery methods
Normally, we need to back up a database. First, we need to disconnect the database from the running data server, or stop the entire database server, and then copy the file.
Command for removing the database: Sp_detach_db Database Name
Command for connecting to the database: Sp_attach_db or sp_attach_single_file_db
S_attach_db [@ dbname =] 'dbname', [@ filename1 =] 'filename _ n' [,... 16]
Sp_attach_single_file_db [@ dbname =] 'dbname', [@ physname =] 'physical _ name'
This method can be used to correctly restore the database files of SQL Sever7.0 and SQL Server 2000. The key point is that the mdf and ldf files must be backed up during backup. The mdf file is the database data file, ldf is a database log file.
Example:
Assume that the database is test, the data file is test_data.mdf, and the log file is test_log.ldf. Next we will discuss how to back up and restore the database.
Detach a database: sp_detach_db 'test'
Connect to the database: sp_attach_db 'test', 'c: Program FilesMicrosoft SQL ServerMSSQLDatatest_data.mdf ', 'c: Program FilesMicrosoft SQL servermssqldatatest_log.ldf'
Sp_attach_single_file_db 'test', 'c: Program FilesMicrosoft SQL ServerMSSQLDatatest_data.mdf'
// This article