-- This query will rollback any transaction which is running on that database
-- and bring SQL Server database in a "single user" mode
ALTER DATABASE DATABASENAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
-- Marking database READ_ONLY, disable logging,
-- and limiting access only to members of the sysadmin fixed server role
ALTER DATABASE DATABASENAME SET EMERGENCY
-- Checks the logical and physical integrity of all the objects in the specified database
DBCC checkdb(DATABASENAME)
-- In case of simple failure then we can use allow data loss option to recover Database
-- DBCC CheckDB (DATABASENAME, REPAIR_ALLOW_DATA_LOSS)
-- Set database accessibility to it's original state, allowing all logins
ALTER DATABASE DATABASENAME SET MULTI_USER
ALTER
DATABASE
DATABASENAME SET
ONLINE
;
EXEC sp_resetstatus DATABASENAME