--database is occupied cannot be restored workaround:--1 , set the database to work in single-user mode. --Set method: Right-click on the database you want to restore, select Properties-> Options-> Status-> Restrict Access-> "single" On the right-click menu command. This is the menu command for SQLSERVER2005, other versions please find it yourself. --The database is offline on the connection machine use Mastergoalter database DBSET OFFLINE with ROLLBACK immediate--databases offline Goalter db DBSET online---Kill all processes that are using the database use mastergodeclare @dbname varchar set @dbname = ' DB ' declare @sql varchar () declare Cs_ Result cursor local for select ' Kill ' +cast (spid as varchar (a)) from sys.sysprocesses where Db_name (dbid) [Email prot Ected] Open Cs_resultfetch next from Cs_result to @sqlwhile @ @fetch_status =0begin Execute (@sql) FETCH NEXT from CS _result into @sqlendclose cs_resultdeallocate cs_result--------------data log cleanup------------------------change mode alter DATABASE DB SET RECOVERY simplego--shrink DBCC SHRINKFILE (2,30)--30 unit m, log file size go-change mode to full, then change back, if it is already simple, then do not need to Al TER DATABASE DB SET RECOVERY full
Database backup restore, log cleanup code