Notes: [1] Recovering from MDF file to SQL Server database
In the project, if you want to recover data from the MDF database to the SQL Server database, perform the following operations:
1. log on to mssms (Microsoft SQL Server Management studio) to create a database with the same name.
2. Open the directory of the new database and delete its log file test_data.ldf.
3. Open mssms, right-click the database you created, select "task", and select "offline ".
4. Create a query and execute the following statement:
Exec sp_detach_db @ dbname = 'database' exec sp_attach_single_file_db @ dbname = 'database', @ physname = 'e: \ webdemo \ database. MDF'
5. Set the new database to online and refresh the database.
there are three types of files in the Microsoft SQL Server database: 1. Main data files (extension. MDF is the abbreviation of primary data file) the main data file contains the database startup information and points to other files in the database. User Data and objects can be stored in this file, or in secondary data files. Each database has a primary data file. The recommended file extension for main data files is. MDF. Each database of SQL Server is stored in two files. One suffix is MDF, which is a data file and the other suffix is LDF, which is a log file. Therefore, you only need to copy these two files regularly to achieve the backup effect. 2. secondary data files (extension. NDF is short for secondary data files) are optional and user-defined and stored. By placing each file on a different disk drive, secondary files can be used to distribute data to multiple disks. In addition, if the database exceeds the maximum size of a Single Windows file, you can use secondary data files so that the database can continue to grow. The recommended file extension for secondary data files is. NDF. 3. Transaction Log (the extension. LDF is the abbreviation of log data files) stores the log information used to restore the database. Each database must have at least one log file. The recommended file extension for transaction logs is. LDF.