SQL Server – How to Restore MDF without LDF File

restoresql serversql-server-2019

I am trying to attach a database just from the MDF file, cause the server crashed and could never find the LDF. I am on a 2019 MS SQL Server. I am following the instructions from this page. I have created the database, took it offline and swapped my MDF and deleted the created LDF. Then put back online. When I run the following command I get the following:

UPDATE sysdatabases
SET status = 32768
WHERE name = 'MyDB'

Ad hoc updates to system catalogs are not allowed.

I ran the previous command without problems

USE MASTER
GO
sp_CONFIGURE 'allow updates', 1
RECONFIGURE WITH OVERRIDE
GO

Configuration option 'allow updates' changed from 0 to 1. Run the RECONFIGURE statement to install.

Furthermore, if I run the next command, I get the following:

DBCC TRACEON (3604)
DBCC REBUILD_LOG(Database_Name, 'g:\Program Files\Microsoft SQL Server\MSSQL15.AUS\MSSQL\Data\MyDB.ldf')
GO

DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Msg 2526, Level 16, State 3, Line 2
Incorrect DBCC statement. Check the documentation for the correct DBCC syntax and options.

Best Answer

That is not an authoritative source. Please follow Paul Randal's process here, as he's the one who "decided to add a new feature to SQL Server 2005 called EMERGENCY-mode repair".