microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
334 stars 58 forks source link

Add --database flag to sqlcmd query #288

Closed stuartpa closed 1 year ago

stuartpa commented 1 year ago

This closes #287

For sqlcmd create scenario the default_database is set on the user login (in the master database attached to the sqlserver in the container). This means the default_database isn't stored in the sqlconfig file. (this also means we don't have to deal with this value getting out-of-sync between the sqlconfig file and the container instance)

However, a user might delete their default database, which then prevents connecting without specifying a different database (master), to change the default database (this PR also added a # Example on how to do this)

The user might also just want to query a non-default database.

With this PR the user can do

sqlcmd query "PRINT DB_NAME" --database some-other-database

shueybubbles commented 1 year ago
      endpoint.EndpointDetails.Address,

is there no way to put the database name in the endpoint in the config?

How does this path implement the hierarchy of command line switch -> environment variable -> config file?


In reply to: 1458373819


Refers to: internal/sql/mssql.go:37 in f632d34. [](commit_id = f632d3440f704f8b2c12389441b7e3a1c9606f3f, deletion_comment = False)

stuartpa commented 1 year ago
      endpoint.EndpointDetails.Address,

I've added an issue to enable database name to be added to sqlconfig file

https://github.com/microsoft/go-sqlcmd/issues/297


In reply to: 1458373819


Refers to: internal/sql/mssql.go:37 in f632d34. [](commit_id = f632d3440f704f8b2c12389441b7e3a1c9606f3f, deletion_comment = False)