You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Visual Studio 2022数据库项目生成无需SqlCmd的SSMS可执行脚本?

能否在Visual Studio 2022数据库项目中生成仅支持SQL Server Management Studio的脚本?

当然可以,你可以通过调整项目的脚本生成设置,移除SqlCmd相关语法,得到仅能在SQL Server Management Studio(SSMS)中执行的纯T-SQL脚本,操作步骤如下:

  • 打开Visual Studio 2022中的目标数据库项目,右键项目选择发布,或者通过顶部菜单进入「项目」→「生成发布脚本」
  • 在弹出的发布配置窗口中,点击高级按钮
  • 在高级发布设置面板里,找到「部署选项」区域,取消勾选生成SqlCmd脚本选项
  • 确认所有设置后,点击生成脚本,此时输出的就是不含SqlCmd命令的纯T-SQL脚本,完全兼容SSMS执行环境

你提到的默认生成的SqlCmd格式脚本示例如下:

/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF; 
*/
:setvar __IsSqlCmdEnabled "True"

内容的提问来源于stack exchange,提问作者Thomas Koelle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 13:50:17