[ZT]. How to import the MDF file to the sqlserver Database

Source: Internet
Author: User
Tags mssqlserver

 

Task: Import pubs again
You can use sp_attach_db in this way. It is very simple to use pubs to pass the test.

Process:
1. Stop MSSQLServer and run E: \ Program Files \ Microsoft SQL In the MSSQL installation directory.

Server \ MSSQL \ data \ pubs. MDF and E: \ Program Files \ Microsoft SQL Server \ MSSQL \ data \ pubs_log.ldf

Removed.
2. Restart MSSQLServer. in SQL Server Enterprise Manager, you can see that the pubs icon is dimmed with a '(doubt

) 'To delete the pubs. So far, only pubs. MDF is left to simulate the pubs database (pubs_log.ldf is no longer used ).
3. Move pubs. MDF to the MSSQL installation directory e: \ Program Files \ Microsoft SQL Server \ MSSQL \ data \
4. Execute exec sp_attach_db 'pubs', 'e: \ Program Files \ Microsoft SQL in the SQL query Analyzer

Server \ MSSQL \ data \ pubs. MDF ',
There will be an error message:
Device activation error. The physical file name 'E: \ Program Files \ Microsoft SQL Server \ MSSQL \ data \ pubs_log.ldf' can be

Error.
You have created a new log file named 'e: \ Program Files \ Microsoft SQL Server \ MSSQL \ data \ pubs_log.ldf.
It doesn't matter, because the new log file has been created.
This method can be used to reply to the database as long as there is a. MDF file.

 

 

Additional database:

Enterprise Manager
-- Right-click "Database"
-- All tasks
-- Attach a database
-- Select your. MDF file name
-- OK
-- If no. LDF file is displayed and whether to create it, select "yes"

Query the method in Analyzer:
-- Data files and log files
Sp_attach_db 'database name'
, 'Data file name (*. MDF must contain a directory) '-- multiple data files in the database can be separated by commas (,).
, 'Log file name (*. LDF must contain a directory) '-- multiple log files of the database can be separated by commas (,).

-- If only data files exist
Sp_attach_single_file_db 'database name'
, 'Data file name (*. MDF must contain a directory) '-- multiple data files in the database can be separated by commas (,).

 

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.