Today made a very annoying thing, accidentally put a 40 more g of the database log files deleted, and before the deletion I made a log in, dead or alive can not attach to the server has been prompted multiple logs cannot be automatically created, wasted a night of my time, and then constantly Google, Finally in a foreigner's blog found a few statements, directly, thank him on the way to record.
1234567891011 |
USE [master]
GO
-- Method 1: I use this method
EXEC sp_attach_single_file_db @dbname=
‘TestDb‘
,
@physname=N
‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf‘
GO
-- Method 2:
CREATE DATABASE TestDb
ON
(FILENAME = N
‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf‘
)
FOR ATTACH_REBUILD_LOG
GO
|
Statement 1 is to attach the file to the database, and if something like this happens to me. Therefore, the execution of statement 2 can be re-established log, tube several log files.
- Method 3:on= N'C:\Program Files\Microsoft SQL Server\mssql10. Mssqlserver\mssql\data\testdb.mdf')for ATTACHGO
SQL Server attaches a database file without a log file to the servers