所以这是我想要运行的查询
sqlcmd -E -S localhost\MSSQLSERVER_2016 -i C:\Tables.sql
在这个实例中我有多个数据库,当上面的命令运行时,我不知道它针对哪个数据库运行查询。 有什么方法可以使用 sqlcmd 针对我希望它运行的数据库运行吗?
我也尝试过
sqlcmd -E -S localhost\MSSQLSERVER_2016.mydatabase -i C:\Tables.sql
但这没有用。
最佳答案
使用-d
命令行选项指定您的数据库。
-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/