<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 脚本?

        How to pass in parameters to a SQL Server script called with sqlcmd?(如何将参数传递给使用 sqlcmd 调用的 SQL Server 脚本?)
          <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 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)

                    <legend id='FPgei'><style id='FPgei'><dir id='FPgei'><q id='FPgei'></q></dir></style></legend>
                  1. <tfoot id='FPgei'></tfoot>
                        <tbody id='FPgei'></tbody>
                        <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'>