sqlcmd 如何对特定数据库运行查询?

标签 sql sqlcmd

所以这是我想要运行的查询

sqlcmd -E -S localhost\MSSQLSERVER_2016 -i C:\Tables.sql

在这个实例中我有多个数据库,当上面的命令运行时,我不知道它针对哪个数据库运行查询。 有什么方法可以使用 sqlcmd 针对我希望它运行的数据库运行吗?

我也尝试过

sqlcmd -E -S localhost\MSSQLSERVER_2016.mydatabase -i C:\Tables.sql

但这没有用。

最佳答案

使用-d命令行选项指定您的数据库。

Link to the docs.

-d db_name

Issues a USE db_name statement when you start sqlcmd. This option sets the sqlcmd scripting variable SQLCMDDBNAME. This specifies the initial database. The default is your login's default-database property. If the database does not exist, an error message is generated and sqlcmd exits.

关于sqlcmd 如何对特定数据库运行查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51426504/

相关文章:

php - 过滤掉两列等于一的行

powershell - 32 内部错误 "A device attached to the system is not functioning"设置控制台窗口标题时发生 0x1F

c# - 检测是否安装了 SQLCMD.exe 的正确方法?

MySQL Server 5.0 命令行客户端无法打开文件 .sql

sql - 根据角色选择值

sql - 我的 ASP.NET 网站被 SQL 注入(inject)攻击

mysql - 对数字范围 mysql 执行计算

适用于 Windows 2003 的 SQLCMD

sql-server - 从 Ubuntu 连接 SQL Server 时 sqlcmd 登录失败

sql-server - 与 2008 相比,BCP 命令在 SQL Server 2005 中提供不同的输出?