SQL SERVER – Maintenance Activity – Attach mdf file without ldf file

Posted: May 13, 2012 in Uncategorized

Following command will take care of creating the new db using existing single data file. This command will also creates a new log file and you can ignore previous log files if any in case if it has more initial allotted size which you don’t want to give for new db.
CREATE DATABASE <DB Name> ON
(FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\SS.mdf’)
FOR ATTACH_REBUILD_LOG
GO

You can also use …

EXEC sp_attach_single_file_db @dbname = ‘SAMS_QA’,

@physname = N’C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\SS.mdf’;

Reference – http://blog.sqlauthority.com/2010/04/26/sql-server-attach-mdf-file-without-ldf-file-in-database/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s