Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My database .mdf file got corrupted and I have no means to get my schema s.I tried with a few soft wares available on the internet but its turns out that all of them being demo versions don't give back the repaired file.Is there any other means by which I can restore my db? I am using MS SQL 2008

share|improve this question
5  
You need either a backup or a fat bank account. – Remus Rusanu 7 hours ago
This question's comments have information about the very same problem stackoverflow.com/questions/12242017/… – Marcello Romani 7 hours ago
@MarcelloRomani i have detach database so now this is not working – sangram parmar 7 hours ago
This user lalitcdhake.blogspot.com/2012/09/… says he moved the mdf and log files to another server machine and attached them to the sql server instance running on that machine, plus he run a script that "fixed" the db. Hope this helps... – Marcello Romani 7 hours ago

closed as off topic by gbn, Arvo, Ken White, Luc M, SysDragon 4 hours ago

Questions on Stack Overflow are expected to relate to programming or software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote -1 down vote accepted

Go ahead and delete your .ldf file.

Then Execute the below scripts.There are three.So choose one according to your condition.

-- Method 1

 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\MSSQ\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

Method 2: If one or more log files are missing, they are recreated again.

There is one more method which I am demonstrating here but I have not used myself before. According to Book Online, it will work only if there is one log file that is missing. If there are more than one log files involved, all of them are required to undergo the same procedure.

-- Method 3:

CREATE DATABASE TestDb ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf')
FOR ATTACH
GO

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

share|improve this answer
2  
Pretty much any answer beginning "Go ahead and delete your .ldf file" without any kind of caveats of disclaimer is worth a downvote. Also I don't see how trying to reattach the mdf without the ldf will help at all as it is the mdf file that is corrupted. – Martin Smith 7 hours ago
i deleted ldf file.. method 1 is working for me thanx rajan – sangram parmar 7 hours ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.