在部署后脚本中处理 SQLCMD :r

发布于 2024-07-15 14:45:26 字数 464 浏览 7 评论 0原文

我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只等公子 2024-07-22 14:45:26

事实证明,只需指定脚本文件的相对路径就足够了。 我被 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文