BAT Operations Database (Append, detach, delete, restore)

Source: Internet
Author: User
Tags goto

BAT Code:

@echo offTitle DataBase Color 0A: Caozuo  Echo.Echo═══════════════════════════════════════Echo"Database Operations":Echo1.Deleting a databaseEcho2.Restoring a databaseEcho3.Action 3Echo4.Action 4Echo5.Action 5Set/P n=Enter the operation number:if"%n%" = = ""CLS&Goto : Caozuo if"%n%" = = "1"Pager: 1if"%n%" = = "2"Pager: 2if"%n%" = = "3"Pager: 3if"%n%" = = "4"Pager: 4if"%n%" = = "5"Pager: 5if/I "%n%" = = "N"Exit Pause Goto : EOF :1Echo.Delete the database start .... @osql .. Exe/usa/[email protected]/slocalhost/dmaster/i C:\Users\310171611\Desktop\142\database\DropDB.SQLEcho.Delete the end of the database ...Goto : Caozuo :2Echo.Restore the database start .... @osql .. Exe/usa/[email protected]/slocalhost/dmaster/i C:\Users\310171611\Desktop\142\database\RestoreDB.SQLEcho.Restore the end of the database ...Goto : Caozuo  Goto : Caozuo :3EchoAction 3Goto : Caozuo :4EchoAction 4Goto : Caozuo:5EchoAction 5Goto : Caozuo


BAT file is called DOS command osql, you can modify the corresponding link string to

Restoredb.sql,dropdb.sql is a common SQL file that can be replaced with any SQL

Dropdb.sql

 UseMasterGoAlter DatabaseDbemsSetSingle_user with rollbackImmediate--Roll back the database to the original configuration stateGoDrop DatabaseDbems--Deleting a databaseGO UseMasterGoAlter DatabaseDbemsconfigSetSingle_user with rollbackImmediate--Roll back the database to the original configuration stateGoDrop DatabaseDbemsconfig--Deleting a databaseGO

Restoredb.sql

 UseMASTERGoif db_id('Dbems') is  not NULLDROP DATABASEDbemsGOCreate DATABASEDbemsRESTORE DATABASEDbems from DISK = 'C:\Users\310171611\Desktop\142\database\dbEMS_A.bak'    withMOVE'Dbems'  to 'C:\database\dbEMS.mdf', MOVE'Dbems_log'  to 'C:\database\dbEMS_log.ldf', STATS= Ten,REPLACE GODeclare @msg varchar( -)if(@ @ERROR <> 0 )begin   Select @msg=Convert(Char( -),getdate(),9)+'-----dbems Restore data failed or an exception occurred'   Print @msgEndElsebegin   Select @msg=Convert(Char( -),getdate(),9)+'-----dbems Database Restore Complete'   Print @msgEND------------------------------------------------------------------------- UseMASTERGoif db_id('Dbemsconfig') is  not NULLDROP DATABASEDbemsconfigGOCreate DATABASEDbemsconfigRESTORE DATABASEDbemsconfig from DISK = 'C:\Users\310171611\Desktop\142\database\dbEMSConfig_A.bak'    withMOVE'Dbemsconfig'  to 'C:\database\dbEMSConfig.mdf', MOVE'Dbemsconfig_log'  to 'C:\database\dbEMSConfig_log.ldf', STATS= Ten,REPLACE GODeclare @msg varchar( -)if(@ @ERROR <> 0 )begin   Select @msg=Convert(Char( -),getdate(),9)+'-----dbemsconfig Restore data failed or an exception occurred'   Print @msgEndElsebegin   Select @msg=Convert(Char( -),getdate(),9)+'-----dbemsconfig Database Restore Complete'   Print @msgEnd

Additional, detached features everyone can write SQL scripts according to their own situation.

BAT Operations Database (Append, detach, delete, restore)

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.