Database backup restore, log cleanup code

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.