SQLCMD 模式 - 'S' 附近的语法不正确

SQLCMD MODE - Incorrect syntax near 'S'

在 SSMS 中,当我执行

sqlcmd -S "flynetSrv"

我得到:

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'S'.

我已经通过 SSMS 连接到服务器

我也试过了

sqlcmd -d "dbname1"

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'd'.

请帮忙?

sqlcmd 是一个 utility intended to be used in a command prompt

您不能在 SQL Server Management Studio (SSMS) 查询中使用它 window

您只能在查询 window 中编写或编辑 SQLCMD 脚本,启用 SQLCMD 模式(查询菜单 -> SQL命令模式)

来自 MSDN - Editing SQLCMD Scripts with Query Editor:

To use the Database Engine Query Editor to write or edit SQLCMD scripts, you must enable the SQLCMD scripting mode.