• <small id='7Sii3'></small><noframes id='7Sii3'>

  • <i id='7Sii3'><tr id='7Sii3'><dt id='7Sii3'><q id='7Sii3'><span id='7Sii3'><b id='7Sii3'><form id='7Sii3'><ins id='7Sii3'></ins><ul id='7Sii3'></ul><sub id='7Sii3'></sub></form><legend id='7Sii3'></legend><bdo id='7Sii3'><pre id='7Sii3'><center id='7Sii3'></center></pre></bdo></b><th id='7Sii3'></th></span></q></dt></tr></i><div id='7Sii3'><tfoot id='7Sii3'></tfoot><dl id='7Sii3'><fieldset id='7Sii3'></fieldset></dl></div>
      <bdo id='7Sii3'></bdo><ul id='7Sii3'></ul>

    <legend id='7Sii3'><style id='7Sii3'><dir id='7Sii3'><q id='7Sii3'></q></dir></style></legend>

  • <tfoot id='7Sii3'></tfoot>

      1. 使用批处理文件执行一组 SQL 查询?

        Executing set of SQL queries using batch file?(使用批处理文件执行一组 SQL 查询?)

          <tbody id='FvF82'></tbody>

        <small id='FvF82'></small><noframes id='FvF82'>

            • <tfoot id='FvF82'></tfoot>

            • <legend id='FvF82'><style id='FvF82'><dir id='FvF82'><q id='FvF82'></q></dir></style></legend>
              <i id='FvF82'><tr id='FvF82'><dt id='FvF82'><q id='FvF82'><span id='FvF82'><b id='FvF82'><form id='FvF82'><ins id='FvF82'></ins><ul id='FvF82'></ul><sub id='FvF82'></sub></form><legend id='FvF82'></legend><bdo id='FvF82'><pre id='FvF82'><center id='FvF82'></center></pre></bdo></b><th id='FvF82'></th></span></q></dt></tr></i><div id='FvF82'><tfoot id='FvF82'></tfoot><dl id='FvF82'><fieldset id='FvF82'></fieldset></dl></div>
                <bdo id='FvF82'></bdo><ul id='FvF82'></ul>

                  本文介绍了使用批处理文件执行一组 SQL 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用的是 SQL Server 数据库.我有这些 SQL 查询:

                  I am using a SQL Server database. I have these SQL queries:

                  Delete from TableA;
                  Delete from TableB;
                  Delete from TableC;
                  Delete from TableD;
                  Delete from TableE;
                  

                  是否可以使用批处理文件运行这些脚本?数据库是远程数据库.

                  Is it possible to run these scripts using a batch file? The database is a remote database.

                  谢谢!

                  推荐答案

                  将命令保存在 .SQL 文件中,例如:ClearTables.sql,在您的 .SQL 文件中说代码>C: emp 文件夹.

                  Save the commands in a .SQL file, ex: ClearTables.sql, say in your C: emp folder.

                  内容 C:TempClearTables.sql

                  Delete from TableA;
                  Delete from TableB;
                  Delete from TableC;
                  Delete from TableD;
                  Delete from TableE;
                  

                  然后使用sqlcmd执行如下.既然您说数据库是远程的,请使用以下语法(更新服务器和数据库实例名称后).

                  Then use sqlcmd to execute it as follows. Since you said the database is remote, use the following syntax (after updating for your server and database instance name).

                  sqlcmd -S <ComputerName><InstanceName> -i C:TempClearTables.sql
                  

                  例如,如果您的远程计算机名称是 SQLSVRBOSTON1 并且数据库实例名称是 MyDB1,那么命令应该是.

                  For example, if your remote computer name is SQLSVRBOSTON1 and Database instance name is MyDB1, then the command would be.

                  sqlcmd -E -S SQLSVRBOSTON1MyDB1 -i C:TempClearTables.sql
                  

                  另请注意,-E 指定默认身份验证.如果您有要连接的用户名和密码,请使用 -U-P 开关.

                  Also note that -E specifies default authentication. If you have a user name and password to connect, use -U and -P switches.

                  您将通过打开 CMD 命令窗口来执行所有这些操作.

                  You will execute all this by opening a CMD command window.

                  使用批处理文件.

                  如果要保存成批处理文件,双击运行,如下操作.

                  If you want to save it in a batch file and double-click to run it, do it as follows.

                  像这样创建并保存ClearTables.bat.

                  echo off
                  sqlcmd -E -S SQLSVRBOSTON1MyDB1 -i C:TempClearTables.sql
                  set /p delExit=Press the ENTER key to exit...:
                  

                  然后双击它运行它.它将执行命令并等待您按某个键退出,以便您可以看到命令输出.

                  Then double-click it to run it. It will execute the commands and wait until you press a key to exit, so you can see the command output.

                  这篇关于使用批处理文件执行一组 SQL 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  1. <tfoot id='UNjKJ'></tfoot>
                  2. <i id='UNjKJ'><tr id='UNjKJ'><dt id='UNjKJ'><q id='UNjKJ'><span id='UNjKJ'><b id='UNjKJ'><form id='UNjKJ'><ins id='UNjKJ'></ins><ul id='UNjKJ'></ul><sub id='UNjKJ'></sub></form><legend id='UNjKJ'></legend><bdo id='UNjKJ'><pre id='UNjKJ'><center id='UNjKJ'></center></pre></bdo></b><th id='UNjKJ'></th></span></q></dt></tr></i><div id='UNjKJ'><tfoot id='UNjKJ'></tfoot><dl id='UNjKJ'><fieldset id='UNjKJ'></fieldset></dl></div>
                    <legend id='UNjKJ'><style id='UNjKJ'><dir id='UNjKJ'><q id='UNjKJ'></q></dir></style></legend>
                      <bdo id='UNjKJ'></bdo><ul id='UNjKJ'></ul>

                          <tbody id='UNjKJ'></tbody>

                            <small id='UNjKJ'></small><noframes id='UNjKJ'>