如何将参数传递给使用 sqlcmd 调用的 SQL Server 脚本?
是否可以将参数传递给 SQL Server 脚本?我有一个创建数据库的脚本。它是使用 sqlcmd 从批处理文件中调用的。该 SQL 脚本的一部分如下:
CREATE DATABASE [SAMPLE] ON PRIMARY
( NAME = N'SAMPLE', FILENAME = N'c:\dev\SAMPLE.mdf' , SIZE = 23552KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'SAMPLE_log', FILENAME = N'c:\dev\SAMPLE_log.ldf' , SIZE = 29504KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
我希望能够传递数据库和日志的文件名,这样我就不必硬编码“C:\dev\SAMPLE.mdf”和“C:\dev” \SAMPLE_log.ldf'。
有办法做到这一点吗?我正在运行 Microsoft SQL Server 2008 Express。如果您需要更多信息,请告诉我。
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:\dev\SAMPLE.mdf' , SIZE = 23552KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'SAMPLE_log', FILENAME = N'c:\dev\SAMPLE_log.ldf' , SIZE = 29504KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
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:\dev\SAMPLE.mdf' and 'C:\dev\SAMPLE_log.ldf'.
Is there a way to do this? I am running Microsoft SQL Server 2008 Express. Let me know if you need any more information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 -v 开关传入变量。
然后在你的脚本文件中
Use the -v switch to pass in variables.
Then in your script file