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)