Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidsheardown/82fb5d6dc095900084057a210e950771 to your computer and use it in GitHub Desktop.
Save davidsheardown/82fb5d6dc095900084057a210e950771 to your computer and use it in GitHub Desktop.
How to recover MS-SQL suspect database
SELECT DATABASEPROPERTYEX (N'SQL-Examples', N'STATUS') AS N'Status';
ALTER DATABASE [SQL-Examples] SET EMERGENCY;
GO
ALTER DATABASE [SQL-Examples] SET SINGLE_USER;
GO
DBCC CHECKDB (N'SQL-Examples', REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;
GO
-- Remember to set back to multi-user
ALTER DATABASE [SQL-Examples] SET MULTI_USER;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment