如何从批处理文件运行.sql 文件?

发布于 2024-09-10 20:33:26 字数 136 浏览 3 评论 0原文

我正在运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

呢古 2024-09-17 20:33:26

我在另一个问题中回答了这个 /a>:

您应该调用 sqlcmd 批处理文件中的命令行工具。假设您的 sql 文件是“backup.sql”,命令行将类似于:

sqlcmd -E -S yoursqlinstance -i 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:

sqlcmd -E -S yoursqlinstance -i backup.sql

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

荆棘i 2024-09-17 20:33:26

请参阅 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

洛阳烟雨空心柳 2024-09-17 20:33:26

我不使用 SQL Server,但批处理文件只是 DOS 命令的列表。因此,无论您使用什么方式从命令行执行 SQL 文件,都可以在批处理文件中使用。

谷歌快速搜索出现:

sqlcmd -i <inputfile> -o <outputfile>

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:

sqlcmd -i <inputfile> -o <outputfile>
多孤肩上扛 2024-09-17 20:33:26

希望这对您有帮助:

sqlplus UserName/Password@DataBase @C:\sqlFolder\sqlFile.sql

PS:不要忘记添加命令“commit;”在 sql 文件 (sqlFile.sql) 的末尾,此命令命令 Oracle 保存在数据库中执行的更改

Hope this helps you :

sqlplus UserName/Password@DataBase @C:\sqlFolder\sqlFile.sql

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文