Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to restore a SQL Server database marked as "suspect"

Total Hit ( 10828)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


At times a database appears to be marked as "suspect" in the Enterprise Manager. SQL Server marks a database as suspect with it can't access the database. What happens at a low level is that SQL Server sets one of the bits in the status field in the sysdatabases table.

In general, this problem has no trivial solution. A simpler case occurs when the file that hosts the database is renamed from the command prompt or Windows Explorer. In this case, you just have to restore the original file name and then manually restore the bit in the status field with this command:

Click here to copy the following block
update sysdatabases
set status = status & ~256
where name = 'MySuspectDatabase'

Keep in mind that the command above can be successful only after enabling writing to system tables.
When the error isn't so trivial, you should check the error log to determine whether a restore operation is possible. However, when the data in the transaction log has been damaged, the restore procedure can hardly succeed. In this case the best solution is to restore the database from a recent backup. When this isn't possible, you should bring SQL Server in the so-called emergency mode. This state is entered by setting a bit in the status field in the sysdatabases table. The docs in the Books On Line report that you must OR the field contents with the value 32768, but the correct value is -32768. Thus, this is the command you need:

Click here to copy the following block
update sysdatabases
set status = status | -32768
where name = 'MioSuspectDatabase'

After this command you must stop and restart the SQL Server service. The Emergency Mode prevents SQL Server from restoring the suspect database, which now appears to be available. If the database is now accessible, you should be able to read data using standard techniques, such as a bulkcopy command or SELECT INTO commands.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.