Skip to main content

Posts

Showing posts from January, 2023

How to Create LDF from MDF

If you only have the MDF and it is healthy, you can attach it to your SQL Server. SQL Server will create the database from the .MDF and will create the .LDF for you. Try the following: USE MASTER EXEC sp_attach_single_file_db @dbname = 'YourBank', @physname = 'MDF location'   Microsoft recommends not using this procedure anymore, as it will possibly be discontinued. You can get the same result through CREATE DATABASE with the FOR ATTACH parameter.   USE MASTER CREATE DATABASE MeuBanco ON (NAME='FileLogicalName', FILENAME='FileLocation') FOR ATTACH_REBUILD_LOG IMPORTANT: The wizard does not work, only via script.