SQL script for automatic backup of sqlserver2008 database and execution of script with bat command

Source: Internet
Author: User

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

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.