You are on page 1of 4

SQL Server Interview: How do we troubleshoot database in suspect mode.

What are reasons for database going in suspect mode? It is good to resotre from the available backup. If we donot have backup, follow the below steps: Step 1: Clear the suspect mode of the database using sp_resetstatus DatabaseName. This will clear the suspect flag and make the database available online. Step 2: Change the database status to Emergency using the following command. Emergency mode allows you to access the databases as normal but with no consistency guarantee. This option also allows us to export the table data so that we can minimize the damage. ALTER DATABASE DatabaseName SET EMERGENCY; Step 3: Restrict database to single user by changing the access mode as mentioned below ALTER DATABASE DatabaseName SET SINGLE_USER; Step 4: Run the CHECKDB command with “REPAIR_ALLOW_DATA_LOSS” option. This option should be tried as last option as it always behaves the way it is named. We are not sure of what data it removes. DBCC CHECKDB (DatabaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS; There are some best (simple) practices which prevents us from such failures. Below are some of them     Backup your data frequently ( daily or once in two days) Have multiple backups. Move the backups to external drives or tapes frequently Validate that your backups are good by doing trial restores to alternate server Run CHECKDB regularly

Most common causes for suspect status are missing devices, invalid data files/drives, insufficient disk space, interruption during restore etc. We should see some indication in error log saying what might be cause.

Moving the database files from one drive to another on the same instance.ldf'). USE master. state_desc FROM sys. GO -. . We can user backup and restore or detach and attach to move the files. SELECT name. physical_name AS CurrentLocation. modify the path specified in FILENAME to -.Return the logical file name. GO ALTER DATABASE AdventureWorks2012 SET OFFLINE. SELECT name. GO --Verify the new location. physical_name AS CurrentLocation.master_files WHERE database_id = DB_ID(N'AdventureWorks2012') AND type_desc = N'LOG'. state_desc FROM sys. FILENAME = 'C:\NewLoc\AdventureWorks2008R2_Log.master_files WHERE database_id = DB_ID(N'AdventureWorks2012') AND type_desc = N'LOG'.Physically move the file to a new location. ALTER DATABASE AdventureWorks2012 MODIFY FILE ( NAME = AdventureWorks2012_Log. We can also use the below t-sql statements to move the files. -.the new location of the file on your server. GO -. GO ALTER DATABASE AdventureWorks2012 SET ONLINE.In the following statement.

not updated. the Database Engine marks the database as RESOURCE PENDING. . we must first empty it by relocating any data present in that file to other files in the same filegroup using the command: DBCC shrinkfile(Test_DB. If the log fills during recovery. SQL Server Database Engine issues a 9002 error. Troubleshooting Full Transaction Log(Error 9002) When the transaction log becomes full. If the log fills while the database is online.EmptyFile). we can delete the file and recreate it on the other filegroup. If we want to move to another filegorup. we cannot move the files directly to another filegroup. Or Right click the database goto Reports->Backup and Restore events How to find the last restore date of a database? Use MSDB Select *from RestoreHistory RestoreHistory. user action is required to make log space available. In either case. Once emptied. The log can fill when the database is online or in recovery.How to find last backup taken of a database? Right click on the database goto properties in the general tab we find the last backup taken date and time. How can we move the files from one file group to other? Once a data file is created as part of the filegorup. Or Right click the database goto Reports->Backup and Restore events.This tables maintains the information about the restore history which is in MSDB database. the database remains online but can only be read.