如何从批处理文件运行.sql 文件?
我正在运行 sql server 2008 express,我需要安排一些存储过程每晚运行...所以我已经构建了这些 .sql 文件,我想从 .bat 文件运行它们...我需要知道命令我想,一一执行这些 .sql 文件并存储它们的结果...有人可以帮助我吗?
I am running sql server 2008 express and i need to schedule some stored procedures to run nightly...so i have built out these .sql files which i would want to run from .bat file...i need to know the command to execute these .sql files one by one and store their results i guess...can anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在另一个问题中回答了这个 /a>:
您应该调用 sqlcmd 批处理文件中的命令行工具。假设您的 sql 文件是“backup.sql”,命令行将类似于:
-E
使用可信连接,替换为-U
和-P< /code> 如果您需要指定 SQL 用户名和密码。另请参阅本文的示例。
I answered this in this other question:
You should invoke the sqlcmd command-line tool from your batch file. Assuming your sql file is "backup.sql", the command line would be something like:
-E
uses trusted connection, replace with-U
and-P
if you need to specify a SQL username and password. See also this article with examples.请参阅
sqlcmd
实用程序:http://msdn。 microsoft.com/en-us/library/ms165702.aspx
这允许您从命令行运行 sql 脚本
See the
sqlcmd
utility:http://msdn.microsoft.com/en-us/library/ms165702.aspx
This allows you to run sql scripts from the command line
osql:
http://www.di-mgt.com.au/osqlUtility.htm< /a>
osql:
http://www.di-mgt.com.au/osqlUtility.htm
我不使用 SQL Server,但批处理文件只是 DOS 命令的列表。因此,无论您使用什么方式从命令行执行 SQL 文件,都可以在批处理文件中使用。
谷歌快速搜索出现:
I don't use SQL Server, but a batch file is just a list of DOS commands. So whatever you use to execute SQL files from the commandline can be used in a batch file.
A quick google search turns up:
希望这对您有帮助:
PS:不要忘记添加命令“commit;”在 sql 文件 (sqlFile.sql) 的末尾,此命令命令 Oracle 保存在数据库中执行的更改
Hope this helps you :
P.S : Don't forget to add the command "commit;" at the end of sql file (sqlFile.sql), this command order Oracle to save performed changes in database