21 July 2011

Suspect SQL Server 2000 Database

ProblemI have a SQL Server 2000 database that has the wrong database status. For some reason it is in the 'Suspect/Offline' mode. I just need to correct the problem quickly and get my database back online. How can I do so? Once the status is correct, do I need to take any further steps?

SolutionTo cut to the chase, the script below can be used to correct the SQL Server 2000 database status, but in reality this is only a third of the equation. We also need to correct any sort of corruption and understand why this occurred in the first place.

Database Status Correction Script
The script below will change the database to be in simple recovery mode, which may or may not be the needed configuration for your database. As such, it is necessary to review your database configurations once this script has been executed. In addition, it is necessary to change the 'YourDatabaseName' to your database name in single quotes.

USE Master
GO

-- Determine the original database status
SELECT [Name], DBID, Status
FROM master.dbo.sysdatabases

GO

-- Enable system changes
sp_configure 'allow updates',1
GO
RECONFIGURE WITH OVERRIDE
GO

-- Update the database status
UPDATE master.dbo.sysdatabases

SET Status = 24

WHERE [Name] = 'YourDatabaseName'
GO

-- Disable system changes
sp_configure 'allow updates',0
GO
RECONFIGURE WITH OVERRIDE
GO

-- Determine the final database status
SELECT [Name], DBID, Status
FROM master.dbo.sysdatabases

GO

Check for Corruption
The next step in this process is very key. It is necessary to determine if the database has any corruption and ensure that the database will be able to support the users. If the database has corruption, you may be exposing yourself to more issues by just changing the database status without correcting the underlying issue. To identify the underlying issue, execute the following commands:
  • DBCC CHECKDB - Validate the overall database integrity
  • DBCC CHECKCATALOG - Validate the system catalog integrity
  • DBCC CHECKTABLE - Validate the integrity for a single table
To resolve the issue, you may need to do one or more of the following:
  • Drop and Recreate Index(es)
  • Move the recoverable data from an existing table to a new table
  • Update statistics
  • DBCC UPDATEUSAGE
  • sp_recompile
To ensure the issue is corrected, it is a good idea to re-run the identification commands listed above and validate that they do not have any issues.

Determine the Root Cause
In the long term, it is imperative to understand what caused the suspect/offline database. At a minimum the following questions should be addressed:
  • What has recently changed in your environment?
  • Review your SQL Server logs to see if you can determine when the error occurred.
  • Talk to your team members to ask them what changes have been made.
  • Review your change management and auditing processes to see what has changed in SQL Server or at a systems level.
  • See if the issue has occurred on any other databases in your environment.
Next Steps
  • Although the script from this tip can be easily run, it is necessary to understand why the issue occurred and be sure not to have any corruption moving forward.
  • Heed caution and truly understand the situation before running this script and make sure you do not cause any further issues

No comments: