sql server批处理文件执行 [英] sql server batch file execution

查看:136
本文介绍了sql server批处理文件执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在sql server中使用批处理文件执行脚本文件

How do I execute the script file using batch file in sql server

推荐答案

如果要从命令行执行脚本,是一个很好的工具="http://msdn.microsoft.com/en-us/library/ms162773.aspx"> sqlcmd [
If you mean executing a script from command line, one excellent tool is sqlcmd[^] utility.

You can pass the script as a parameter along with all credentials etc.


1.在对象资源管理器中,连接到SQL Server数据库引擎的实例,然后展开该实例.
2.展开SQL Server代理,创建一个新作业,或右键单击一个现有作业,然后单击属性".有关创建作业的更多信息.
3.在作业属性"对话框中,单击步骤"页面,然后单击新建".
4.在新建作业步骤"对话框中,输入作业步骤名称.
5.在类型"列表中,选择操作系统(CmdExec)".
6.在运行方式"列表中,选择具有该作业将使用的凭据的代理帐户.默认情况下,CmdExec作业步骤在SQL Server代理服务帐户的上下文下运行.
7.在成功命令的处理退出码"框中,输入0到999999之间的一个值.
8.在命令"框中,输入操作系统命令或可执行程序.
9.单击高级"页面以设置作业步骤选项,例如:如果作业步骤成功或失败,将执行什么操作; SQL Server代理应尝试执行该作业步骤的次数;以及SQL Server代理可以在其中写入的文件作业步骤输出.只有sysadmin固定服务器角色成员才能将作业步骤输出写入操作系统文件.
1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
2. Expand SQL Server Agent, create a new job or right-click an existing job, and then click Properties.For more information about creating a job.
3. In the Job Properties dialog, click the Steps page, and then click New.
4. In the New Job Step dialog, type a job Step name.
5. In the Type list, choose Operating system (CmdExec).
6. In Run as list, select the proxy account with the credentials that the job will use. By default, CmdExec job steps run under the context of the SQL Server Agent service account.
7. In the Process exit code of a successful command box, enter a value from 0 to 999999.
8. In the Command box, enter the operating system command or executable program.
9. Click the Advanced page to set job step options, such as: what action to take if the job step succeeds or fails, how many times SQL Server Agent should try to execute the job step, and the file where SQL Server Agent can write the job step output. Only members of the sysadmin fixed server role can write job step output to an operating system file.


1)打开记事本
2)编写以下命令.如果您不想传递参数,请排除Var.用您的过程名称替换过程名称
1) Open Notepad
2) Write below command. Ecxclude Var if you don''t want to pass parameter. Replace procedure name with you procedure name
SET var=Parameters
BCP "EXEC ProcedureName '%var%' " -t`~ -c -T


3)将此文件另存为批处理文件".bat"

就这样


3) Save this file as batch file ".bat "

That''s it


这篇关于sql server批处理文件执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆