Below is another solution how to recover a Database by using MDF file.
==================================================
/*
1)------ Very Important Step ------ create a new database of the same name and log file and location as the old database and log file
get rid or rename the old database.
2)----- Very Important Step ------ create a new database of the right size and shape with correct log and data file locations
3) stop sql server in service manager
4) rename the new databases.mdf or delete it if you don't have enough space - do not touch the .ldf
5) move back in the old database .mdf file or rename it back again
6) restart sql server
7) it should come up suspect
8) After this run the below query in the master DB
-- Note -- I have used 'ABCDEF' as an example in the below query, replace it with the DB which you want to recover.
*/
EXEC sp_configure 'allow updates', 1
RECONFIGURE WITH OVERRIDE
GO
BEGIN TRAN
UPDATE master..sysdatabases
SET status = status | 32768
WHERE filename = 'E:\Data\ABCDEF_Data.MDF'
IF @@ROWCOUNT = 1
BEGIN
COMMIT TRAN
RAISERROR('emergency mode set', 0, 1)
END
ELSE
BEGIN
ROLLBACK
RAISERROR('unable to set emergency mode', 16, 1)
END
GO
EXEC sp_configure 'allow updates', 0
RECONFIGURE WITH OVERRIDE
GO
-- Restart SQL Server at this point.
DBCC REBUILD_LOG('ABCDEF','E:\Data\ABCDEF_Log.ldf')
/*Perform physical and logical integrity checks at this point.
Bcp data out if your integrity checks demonstrate that problems exist.
*/
ALTER DATABASE ABCDEF SET MULTI_USER
GO
GO
==================================================
here 'E:\' is my drive where the data is stored
Sunday, March 1, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment