How to Attach a Database MDF Only

For databases with single log files, the sp_attach_single_file_db stored procedure will work to attach the DB file and create a new single log file. The syntax is as follows:

sp_attach_single_file_db [ @dbname= ] ‘dbname’, [ @physname= ] ‘physical_name’

Where there are multiple log file, the above stored proc won’t work. You can still attach this using the following method:

USE [master]
GO
CREATE DATABASE [DatabaseName] ON
( FILENAME = N’C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataDatabaseToBeAttached.mdf’ )
FOR ATTACH_REBUILD_LOG
GO