<tfoot id='uzYye'></tfoot>

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

    • <bdo id='uzYye'></bdo><ul id='uzYye'></ul>
    <legend id='uzYye'><style id='uzYye'><dir id='uzYye'><q id='uzYye'></q></dir></style></legend>

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

        如何将参数传递给使用 sqlcmd 调用的 SQL Server 脚本?

        时间:2024-04-15
          <tbody id='K1Cqn'></tbody>

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

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

                  本文介绍了如何将参数传递给使用 sqlcmd 调用的 SQL Server 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以将参数传递给 SQL Server 脚本?我有一个创建数据库的脚本.它是使用 sqlcmd 从批处理文件中调用的.该 SQL 脚本的一部分如下:

                  Is it possible to pass parameters to a SQL Server script? I have a script that creates a database. It is called from a batch file using sqlcmd. Part of that SQL script is as follows:

                  CREATE DATABASE [SAMPLE] ON  PRIMARY 
                  ( NAME = N'SAMPLE', FILENAME = N'c:devSAMPLE.mdf' , SIZE = 23552KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
                   LOG ON 
                  ( NAME = N'SAMPLE_log', FILENAME = N'c:devSAMPLE_log.ldf' , SIZE = 29504KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
                  

                  我希望能够传入数据库和日志的文件名,这样我就不必硬编码C:devSAMPLE.mdf"和C:devSAMPLE_log.ldf".

                  I want to be able to pass in the filenames for the database and the log so that I don't have to hardcode 'C:devSAMPLE.mdf' and 'C:devSAMPLE_log.ldf'.

                  有没有办法做到这一点?我正在运行 Microsoft SQL Server 2008 Express.如果您需要更多信息,请告诉我.

                  Is there a way to do this? I am running Microsoft SQL Server 2008 Express. Let me know if you need any more information.

                  推荐答案

                  使用 -v 开关传入变量.

                  Use the -v switch to pass in variables.

                  sqlcmd -v varMDF="C:devSAMPLE.mdf" varLDF="C:devSAMPLE_log.ldf"
                  

                  然后在你的脚本文件中

                  CREATE DATABASE [SAMPLE] ON  PRIMARY 
                  ( NAME = N'SAMPLE', FILENAME = N'$(varMDF)' , SIZE = 23552KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
                   LOG ON 
                  ( NAME = N'SAMPLE_log', FILENAME = N'$(varLDF)' , SIZE = 29504KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
                  

                  这篇关于如何将参数传递给使用 sqlcmd 调用的 SQL Server 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“订购者"使用列名参数 下一篇:使用 Dapper 删除超过 2100 行(按 ID)的正确方法

                  相关文章

                    <legend id='FPgei'><style id='FPgei'><dir id='FPgei'><q id='FPgei'></q></dir></style></legend>
                  1. <tfoot id='FPgei'></tfoot>
                      <bdo id='FPgei'></bdo><ul id='FPgei'></ul>

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

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