Skip to content

Instantly share code, notes, and snippets.

@Ja7ad
Created December 2, 2020 12:44
Show Gist options
  • Save Ja7ad/29fe115b43665cabdeca19633b91ca61 to your computer and use it in GitHub Desktop.
Save Ja7ad/29fe115b43665cabdeca19633b91ca61 to your computer and use it in GitHub Desktop.
Find invalid records in your database and remove record, Eventually repair your database
USE master
SELECT NAME,STATE_DESC FROM SYS.DATABASES
WHERE STATE_DESC='SUSPECT'
USE master
"Replace your database name with Your_Database_Name"
ALTER DATABASE Your_Database_Name SET EMERGENCY
DBCC CHECKDB (Your_Database_Name)
ALTER DATABASE Your_Database_Name SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CHECKDB (Your_Database_Name, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE Your_Database_Name SET MULTI_USER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment