How to attempt a database to be marked as restoring
/****
By select left (' Claro ', 2), in Xian, 2009-03-27 00:29:23.450
Microsoft SQL Server 2005-9.00.1406.00
(Intel X86)
Mar 3 2007 18:40:02
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790:service Pack 2)
****/
Use [master]
Go
-->1. Querying database status
Select State_desc,name,user_access_desc from sys.databases where name= ' db '
--state_desc name User_access_desc
--restoring Db Multi_user
-->2. Modify Database state
ALTER DATABASE [Db] SET ONLINE
--Message 5052, Level 16, State 1, line 1th
--The ALTER database is not allowed when the databases are in restoring state.
--Message 5069, Level 16, State 1, line 1th
The--alter DATABASE statement failed.
-->3. Set the database status to Emergency recovery mode
ALTER DATABASE [Db] SET Emergency
--Message 5052, Level 16, State 1, line 1th
--The ALTER database is not allowed when the databases are in restoring state.
--Message 5069, Level 16, State 1, line 1th
The--alter DATABASE statement failed.
-->4. Set database status to Single-user mode
ALTER DATABASE [Db] SET Single_user
--Message 5052, Level 16, State 1, line 1th
--The ALTER database is not allowed when the databases are in restoring state.
--Message 5069, Level 16, State 1, line 1th
The--alter DATABASE statement failed.
-->5.CHECKDB Inspection
DBCC CHECKDB (Db,repair_allow_data_loss)
--Message 927, Level 14, State 2, line 1th
--Cannot open database ' Db '. The database is being restored.
-->6. Trying to continue the restore with a backup set
RESTORE DATABASE [Db] from DISK = N ' C:/db.bak ' with FILE = 1, Nounload, REPLACE, STATS = 10
Go
--13 has been processed.
--22 has been processed.
--31 has been processed.
--40 has been processed.
--54 has been processed.
--63 has been processed.
--72 has been processed.
--81 has been processed.
--90 has been processed.
--100 has been processed.
--176 pages have been processed for database ' db ', file ' db ' (located on file 1).
--2 pages have been processed for database ' Db ', file ' db_LOG ' (located on file 1).
--restore DATABASE successfully processed 178 pages, costing 0.159 seconds (9.125 mb/sec).
-->7. Check Database status
Select State_desc,name,user_access_desc from sys.databases where name= ' db '
--state_desc name User_access_desc
--online Db Multi_user
--This DB database is normal. The way the database is repaired after subsequent attempts to state the database in doubt.