Search

Wednesday, July 27, 2011

Fix code for suspect database

If a databse is in suspect code, this code can correct it. Note after you have run ALTER DATABASE MYDB SET EMERGENCY, run each of the following rows one by one. If checkdb is reproitng errros you migh try with the the DBCC CheckDB ('MYDB', REPAIR_ALLOW_DATA_LOSS)

Note!!! That will realy remove any pages, linsk etc that are corupted and remove that data that where there. This will for sure lead to missing data. Ins ome cases this is however the only choice. If there is an backup it is a better choice to use that in the first place.

EXEC sp_resetstatus 'MYDB';
ALTER DATABASE MYDB SET EMERGENCY
DBCC checkdb('MYDB')
ALTER DATABASE MYDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('MYDB', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE MYDB SET MULTI_USER
ALTER DATABASE MYDB SET online

No comments:

Post a Comment