Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to repair Microsoft SQL database  (Read 3432 times)

0 Members and 1 Guest are viewing this topic.

sajugovind

  • Guest
How to repair Microsoft SQL database
« on: July 19, 2014, 05:29:07 pm »
How to repair a corrupted database? It's very easy to repair a MySql database, but in the case of MSSQL we need to follow a couple of steps.

In MS SQL Studio run new query:

1. dbcc checkdb(‘DB-NAME’) with no_infomsgs

DB-NAME is a name of your corrupted database. If this is completed without any errors then the database does not need to be repaired.

2. Alter database DB-NAME set SINGLE_USER

Before we begin repairing the database, the database must be set in single user mode.

3. dbcc checkdb(‘DB-NAME’,REPAIR_REBUILD)

There are number of repair model usually we use first REPAIR_REBUILD. When everything is ok go to step 5.e (multi user mode) If not, go to next step.

4. dbcc checkdb(‘DB-NAME’,REPAIR_ALLOW_DATA_LOSS)

This command may cause data loss. When everything is ok go to step 5.e (multi user mode) If not, go to next step.

5.

a. ALTER DATABASE DB-NAME SET EMERGENCY
b. ALTER DATABASE DB-NAME SET SINGLE_USER
c. DBCC CHECKDB (DB-NAME, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS
d. ALTER DATABASE DB-NAME SET ONLINE
e. ALTER database DB-NAME set MULTI_USER

Description:
a. Set database to emergency mode
b. Set database to single user mode
c. Check database and repair with allow data loss
d. Back database to online mode from emergency mode
e. Set database to multi user mode for normal use

Thank you,