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 (,).