如何在SQL Server Express版中创建作业 [英] How to create jobs in SQL Server Express edition
问题描述
任何人都可以向我解释如何在SQL Server Express
版中创建职位吗?
Could anyone please explain to me how to create jobs in SQL Server Express
edition?
推荐答案
SQL Server Express 不会包括SQL Server代理,因此无法仅创建SQL代理作业.
SQL Server Express doesn't include SQL Server Agent, so it's not possible to just create SQL Agent jobs.
您可以做的是:
您可以手动"创建作业.通过创建批处理文件和SQL脚本文件,然后通过Windows Task Scheduler运行它们.
例如,您可以使用两个文件备份数据库,如下所示:
What you can do is:
You can create jobs "manually" by creating batch files and SQL script files, and running them via Windows Task Scheduler.
For example, you can backup your database with two files like this:
backup.bat:
sqlcmd -i backup.sql
backup.sql:
backup database TeamCity to disk = 'c:\backups\MyBackup.bak'
只需将两个文件放入同一文件夹中,然后通过Windows Task Scheduler执行批处理文件即可.
Just put both files into the same folder and exeute the batch file via Windows Task Scheduler.
第一个文件只是Windows批处理文件,它调用 sqlcmd实用程序并传递一个SQL脚本文件.
SQL脚本文件包含T-SQL.在我的示例中,备份数据库只是一行,但是您可以在其中放入任何T-SQL.例如,您可以改为执行某些UPDATE
查询.
The first file is just a Windows batch file which calls the sqlcmd utility and passes a SQL script file.
The SQL script file contains T-SQL. In my example, it's just one line to backup a database, but you can put any T-SQL inside. For example, you could do some UPDATE
queries instead.
如果您要创建的作业是用于备份,索引维护或完整性检查的,则还可以使用出色的维护解决方案由奥拉·哈伦格伦(Ola Hallengren)
If the jobs you want to create are for backups, index maintenance or integrity checks, you could also use the excellent Maintenance Solution by Ola Hallengren.
它由一堆存储过程(以及SQL Server非Express版本的SQL Agent作业)以及常见问题解答中有关于如何在SQL Server Express上运行作业的部分:
It consists of a bunch of stored procedures (and SQL Agent jobs for non-Express editions of SQL Server), and in the FAQ there’s a section about how to run the jobs on SQL Server Express:
如何开始使用SQL Server Express上的SQL Server维护解决方案?
SQL Server Express没有SQL Server代理.因此,必须使用cmd文件和Windows Scheduled Tasks调度存储过程的执行.请按照下列步骤.
How do I get started with the SQL Server Maintenance Solution on SQL Server Express?
SQL Server Express has no SQL Server Agent. Therefore, the execution of the stored procedures must be scheduled by using cmd files and Windows Scheduled Tasks. Follow these steps.
SQL Server Express没有SQL Server代理.因此,执行 必须使用cmd文件安排存储过程的调度,并且 Windows计划的任务.请按照下列步骤.
SQL Server Express has no SQL Server Agent. Therefore, the execution of the stored procedures must be scheduled by using cmd files and Windows Scheduled Tasks. Follow these steps.
-
下载MaintenanceSolution.sql.
Download MaintenanceSolution.sql.
执行MaintenanceSolution.sql.该脚本创建所需的存储过程.
Execute MaintenanceSolution.sql. This script creates the stored procedures that you need.
创建cmd文件以执行存储过程;例如:
sqlcmd -E -S.\ SQLEXPRESS -d master -Q执行dbo.DatabaseBackup @Databases ='USER_DATABASES',@Directory =
N'C:\ Backup',@BackupType ='FULL'" -b -o C:\ Log \ DatabaseBackup.txt
Create cmd files to execute the stored procedures; for example:
sqlcmd -E -S .\SQLEXPRESS -d master -Q "EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory =
N'C:\Backup', @BackupType = 'FULL'" -b -o C:\Log\DatabaseBackup.txt
在Windows计划任务中,创建任务以调用cmd文件.
In Windows Scheduled Tasks, create tasks to call the cmd files.
安排任务.
启动任务并确认它们已成功完成.
Start the tasks and verify that they are completing successfully.
这篇关于如何在SQL Server Express版中创建作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!