在 T-SQL 脚本中使用双引号在 SQLCMD 中会失败,但在 SSMO 中不会

发布于 2024-09-29 23:57:57 字数 433 浏览 0 评论 0原文

通过 sqlcmd 执行以下脚本失败。但是,通过 ssmo 或 SQL Server Management Studio 执行它是可行的。

sqlcmd -S . -d test -i input.sql

input.sql:

CREATE FUNCTION test()  
RETURNS  @t TABLE ("ID" INT)  
AS  
BEGIN  
 RETURN  
END  

即使我将 SQL Server Management Studio 置于 sqlcmd 模式,它仍然失败。当我们使用 SSMS 测试脚本但使用 SQLCMD 部署时,这是一个问题。因此,当我们尝试部署时,我们只会发现我们的代码不起作用。

为什么 sqlcmd 会有这样的行为?有什么办法可以关掉它吗?

Executing the following script via sqlcmd fails. However, executing it via ssmo or SQL Server Management Studio works.

sqlcmd -S . -d test -i input.sql

input.sql:

CREATE FUNCTION test()  
RETURNS  @t TABLE ("ID" INT)  
AS  
BEGIN  
 RETURN  
END  

Even when I put SQL Server Management Studio into sqlcmd mode, it still fails. This is a problem as we test our scripts with SSMS, but deploy with SQLCMD. Thus we only find out our code doesn't work when we attempt to deploy.

Why does sqlcmd behave like this? Is there any way to turn it off?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

不美如何 2024-10-06 23:57:57

如果您确实需要在脚本中使用双引号来分隔标识符,则需要在 SQLCMD 通过使用 -Ienable 开关。它在 SQLCMD 中默认为 OFF,但在 SSMS 中默认为 ON,这就是您的测试在 SSMS 中工作的原因。

此处了解有关 QUOTED_IDENTIFIER 的更多信息。

If you really need to use double quotes to delimit identifiers in your scripts, you'd need to set the quoted_identifier option on SQLCMD by using the -Ienable switch. It is OFF by default in SQLCMD but ON by default in SSMS, which is why your tests work in SSMS.

Read more about QUOTED_IDENTIFIER here.

季末如歌 2024-10-06 23:57:57

使用方括号:[ID]

Use square brackets for this: [ID]

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