需要帮助编写在(sql server 2008 和另外 3 个文件中执行 sql 脚本)的 bat 文件。?
我确信之前已经有人问过这些问题,但找不到明确的说明如何创建 批处理文件让我们称之为“更新数据库”这个批处理文件应该
执行位于不同文件夹中的sql脚本 执行另外3个bat文件。
有什么简单的例子如何做到这一点?以前从未做过 非常感谢
编辑
我可以这样做吗?
:On Error exit
:r C:\myPath\MasterUpdateDatabase.bat
GO
SQLCMD -S (Local) -i C:\myPath\InsertUsername.sql
我收到错误:
“GO”未被识别为内部外部命令
感谢您的任何输入
I am sure these has been asked before but cannot find clear instruction how to create a
batch file lets call it "Update Database" this batch file should
Execute sql scripts located in different folders
Execute another 3 bat files.
Any quick examples how to do it?Never done it before
thanks a lot
EDITED
Can I do this?
:On Error exit
:r C:\myPath\MasterUpdateDatabase.bat
GO
SQLCMD -S (Local) -i C:\myPath\InsertUsername.sql
I get an error:
"GO" is not recognized as internal external command
Thanks for any input
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来您正在尝试使用 DOS 命令创建一个批处理文件,该文件要么 (a) 执行其他批处理文件,要么 (b) 执行 SQLCMD 来运行 sql 或 sql 脚本。
这里有几个例子,全部合二为一。我使用带有
/WAIT
开关的 DOS 命令START
,这将使您的原始“主”批处理文件在一个窗口中运行,并在其中执行后续文件或命令一个新窗口。该新窗口将保持打开状态,直到脚本完成并退出。某些
ECHO
可能不是必需的,但脚本现在会与您进行一些对话。因此,这非常简单,您只需运行脚本即可。如果 script1.bat 有断点,您可以将错误返回到主脚本并立即结束。我不清楚这是否是您需要主脚本执行的操作。
这里使用相同的 START /WAIT 来运行 SQLCMD,在本例中仅返回查询结果。这里需要注意的一件事是
-Q
(大写)运行查询并退出。如果您使用-q
(小写),它将运行查询并在 SQLCMD 中打开等待另一个查询。这就是运行 sql 脚本的方式,这就是
-i
所表示的,但我也没有像之前那样在 START /WAIT 中运行它。并不是说你必须这样做,但我想展示这两个例子。这还表明,如果您的脚本返回错误,-b
将结束批处理过程,如果您正在运行多个依赖于前者成功的脚本,这将非常有用。因此,我假设您正在寻找利用 SQLCMD 的 .bat 或 .cmd 文件。我提供的示例非常基本,但希望它能让您走上正确的道路。
哦!请记住,CTRL+C 会破坏正在处理的批处理脚本。
It looks like you're trying to use DOS commands to create a batch file that either (a) executes other batch files or (b) executes SQLCMD to run sql or a sql script.
Here are a couple examples all rolled into one. I'm using the DOS command
START
with the/WAIT
switch, which will keep your original "master" batch file running in one window and execute the subsequent file or commands in a new window. That new window stays open until the script finished AND exits.Some of the
ECHO
s probably aren't required, but the script will talk back to you for now, a little.So, this is pretty simple in the sense that you're just running the script. If you're script1.bat has break points, you can return an error back to the main script and have it end immediately. I wasn't clear if that was what you needed the master script to do.
Here is where did used the same START /WAIT to run SQLCMD, which in this case just returns results from the query. One thing to note here is that the
-Q
(uppercase) runs the query and quits. If you use-q
(lowercase) it will run the query and sit open in SQLCMD waiting for another query.And this is how you can run a sql script, which is what the
-i
denotes, but I also didn't run this in the START /WAIT as earlier. Not that you have to, but I wanted to show both examples. What this also shows is the-b
will end the batch process if your script returns an error, which is useful if you're running multiple scripts that depend on success of the former(s).So, I assumed you were looking for a .bat or .cmd file that utilized SQLCMD. The example I provided is pretty basic, but hopefully it sets you on the right path.
OH! And remember that CTRL+C breaks a batch script in process.
您看到的实际错误是命令行解释器无法识别“GO”,因此您可以删除该行。
The actual error you're seeing is that the command line interpreter does not recognize 'GO', so you could just remove that line.
希望这对您有帮助:
PS:不要忘记添加命令“commit;”在 sql 文件 (InsertUsername.sql) 的末尾,此命令命令 Oracle 保存在 darabase 中执行的更改
Hope this helps you :
P.S : Don't forget to add the command "commit;" at the end of sql file (InsertUsername.sql), this command order Oracle to save performed changes in darabase
这个答案绝对适合您的目的:
sqlcmd -S localhost -U fdmsusr -P fdmsamho -i "E:\brantst\BranchAtt.sql" -o "E:\brantst\branchlog.txt"
This answer definitely works for your purposes:
sqlcmd -S localhost -U fdmsusr -P fdmsamho -i "E:\brantst\BranchAtt.sql" -o "E:\brantst\branchlog.txt"