-----SQL Scripts
DECLARE @fileName varchar (255),--Define the backup file name variable
@dbname varchar (255)--Define the backup database name variable
DECLARE mycursor cursor Fast_forward for select name from master: sysdatabases ORDER BY name--Define a cursor object
Open MyCursor--opening cursors
Set @dbname = ' PYSF '
Set @fileName = ' D:\bakck\1\ ' [email protected]+convert (varchar), GETDATE (), + '. Bak ')--Define the current backup file storage path
Backup Database @dbname to [email protected] loop back up the current databases
FETCH NEXT from MyCursor to @dbname--value again
Close MyCursor--closing cursors
-------------Bat Command
@echo off
Osql-u sa-p 123-d pysf-i. \ data backup script. SQL >log1.log
Pause
------------------
sa--User Name
123--Password
pysf--database name
\ data backup script. SQL---Script name (if both scripts are executed using the Bat command, it is recommended that the SQL script and the bat file are in the same level directory)
SQL script for automatic backup of sqlserver2008 database and execution of script with bat command