SQL Server knowledge center

everything about SQL Server
See also: Other Geeks@INDC

Recover Damaged Database From Data File

Recover Damaged Database From Data File

By : Kasim Wirama, MCDBA

 

This article will show you how to recover database if your backup is not considered valid by SQL Server engine by saying that your database is not clearly shutdown.

 

Typical action you need to do is to restore from full backup and subsequent transaction log backup. Usually this approach works well until you meet some condition that you cannot use your transaction log backup.

 

If you cannot restore transaction log backup, your last chance is recover directly from data file (mdf file), but it doesn’t guarantee database consistency, but still you get your latest data instead of your recover from last full backup.

 

This is unconventional approach, and it should be used as last effort if your database cannot be recovered with typical restore.

 

First you create database with same size, logical and physical name of data file. Next step is that you shutdown SQL Server, override the new data file with the old data file (valid one) and start the SQL Server.

 

After step two is done, your database will be in suspect mode, turn your database mode into emergency and single user only with ALTER DATABASE command.

 

Run DBCC CHECKDB ( your database name, REPAIR_ALLOW_DATA_LOSS) command. After that, bring online your database, and set your database mode to multi user with ALTER DATABASE command.

 

Now your database has been recovered, don’t forget to do full backup soon after your database is online.

Share this post: | | | |

Comments

Joan Black said:

well done mate keep up the good work

# February 21, 2008 10:26 AM

Kasim.Wirama said:

Thanks Joan for your appreciation

# February 21, 2008 5:29 PM

Kusyandi said:

Boleh saran ga Pa Kasim? Mungkin kalo diberi sedikit contoh lengkapnya, maklum saya masih pemula, jadi langkah-2 ada yang kurang saya mengerti. seperty ALTER DATABASE pada posisi emergency dan Single User itu perintahnya seperti apa. soalnya di BOL-nya ga ada contoh untuk recovery.

# February 27, 2008 3:26 PM

Kasim.Wirama said:

oke, untuk ubah database ke mode emergency adalah (asumsi nama database adalah Northwind)

ALTER DATABASE Northwind

SET EMERGENCY;

untuk ubah ke single user querynya adalah :

ALTER DATABASE Northwind

SET SINGLE_USER;

untuk ubah ke multi user querynya adalah :

ALTER DATABASE Northwind

SET MULTI_USER;

untuk ubah ke dbo user querynya adalah :

ALTER DATABASE Northwind

SET RESTRICTED_USER;

untuk ubah database dari emergency ke online querynya dalah :

ALTER DATABASE Northwind

SET ONLINE;

pastikan fokus database dipindahkan ke Master database dengan query :

use Master

go

perintah query ALTER DATABASE hanya ada di SQL Server 2005, coba dicari untuk SQL Server 2000 barangkali ada padanannya.

# March 14, 2008 6:14 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 
Are you human?:  


Enter the numbers above: