在部署后脚本中处理 SQLCMD :r
我们使用 Visual Studio 数据库项目来对数据库架构进行源代码控制。 我们还想编写数据库中某些数据(配置值等)的脚本,因此我们使用自定义命令行实用程序将数据转储到插入脚本中。 一个文件代表一张表的脚本化数据。
有一个特定的 SQL 脚本,称为部署后脚本,它会在项目上的 Deploy 命令之后自动执行。 建议在此处链接其他脚本文件,我们希望链接我们的数据插入脚本。
说明说使用此命令从任意文件解析
SQLCMD :r <filename>
问题是,我不知道我的同事从源代码管理下载它时如何使用它,因为 :r 命令的起始目录是 devenv。 exe(VS dev.env.)位于。
我们是否使用正确的工具从正确的角度处理数据脚本化问题? 如果是这样,那么如何获取正在执行的部署后脚本文件的路径,或者如何解析插入脚本而不将其路径硬编码到部署后脚本中?
We use a Visual Studio Database Project for the source control of the schema of our database. We also want to script certain data (configuration values etc.) from the database, so we use a custom command line utility for dumping data into insert scripts. One file represents one table's scripted data.
There is a certain SQL script, called post-deployment script, which automatically gets executed after the Deploy command on the project. It is recommended to link other script files here, and we'd like to link our data insert scripts.
Instructions say to use this command to parse from arbitrary files
SQLCMD :r <filename>
The problem is, I don't see how my colleagues will be able to use it when they download it from source control, because the start directory for the :r command is where devenv.exe (the VS dev. env.) is located.
Are we approaching the problem of scripting data from the right angle with the right tools? And if it is so, then how can I get the executing post-deployment script file's path, or how can I parse the insert scripts without hard coding their path into the post-deployment script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,只需指定脚本文件的相对路径就足够了。 我被 Visual Studio 的验证 SQL 语法功能误导了,该功能通过使用 devenv.exe 的位置作为起始目录来评估 :r 之后的路径。
但是,当在项目上执行 Deploy 时,:r 命令使用脚本的目录作为起始目录,因此可以使用相对路径轻松给出文件的位置。
Well, it turns out, that simply specifying the relative path to the script file is enough. I got misled by Visual Studio's Validate SQL Syntax feature, which evaluated the path after :r by using devenv.exe's location as a starting directory.
However, when Deploy is executed on the project, the :r command uses the script's directory as the starting directory, so the file's location can be given easily using a relative path.