sqlcmd
$ sqlcmd Official High Risksqlcmd (modern Go-based go-sqlcmd) connects to Microsoft SQL Server, Azure SQL Database, and SQL Managed Instance from the terminal. Agents run headless queries via -Q with -y 0 (to prevent variable-length text/JSON truncation) and -b to fail cleanly on SQL errors.
brew install sqlcmd Direct sqlcmd -Q execution with T-SQL FOR JSON and -b error exit codes avoids heavy multi-tool SQL MCP schemas.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Runs headlessly with -Q and -b, plus -F vertical, -s, and -y 0, though it relies on T-SQL FOR JSON rather than a native CLI --json formatter.
-Q+-bprovides non-interactive execution and error exit codes- No native
--jsonflag; requires T-SQLFOR JSONwith-y 0
Supports SQLCMDPASSWORD and Entra ID auth, though has no client-side --readonly or --dry-run guard against DROP/DELETE queries.
SQLCMDPASSWORDavoids exposing secrets in process args- No client-side read-only SQL guard
Modern go-sqlcmd ships as a single binary via Homebrew, winget, apt, and GitHub releases without ODBC driver headaches.
- Pure Go TDS driver removes legacy ODBC dependency
Full T-SQL access, sqlcmd create mssql local container helpers, and variable substitution (-v).
- Supports scripts (
-i), variables (-v), and local container bootstrap
Official Microsoft repository (microsoft/go-sqlcmd) under MIT license.
- First-party Microsoft Go rewrite
Documented on Microsoft Learn and --help, though legacy C++ vs modern Go sqlcmd docs can occasionally overlap.
- Microsoft Learn reference for
go-sqlcmd
Security, Auth & Guardrails
Supports SQLCMDPASSWORD env var, Entra ID (--authentication-method), Windows integrated auth (-E), and local context config in ~/.sqlcmd/.
MIT open-source CLI; free (requires access to a SQL Server or billable Azure SQL instance).
# sqlcmd Agent Rules - Always pass `-Q` (or `-i`) and `-b` so `sqlcmd` runs non-interactively and exits non-zero on SQL errors. - Pass `-y 0` when querying `FOR JSON` or long `NVARCHAR` columns to avoid 256-char truncation. - Never pass `-P <password>` inline on the command line; use `SQLCMDPASSWORD` env var or Entra ID auth.
Agent-Ready Command Recipes
Safe Read-Only Queries
sqlcmd -S localhost -U sa -b -y 0 -Q "SET NOCOUNT ON; SELECT TOP 20 name, create_date FROM sys.tables FOR JSON AUTO"
Uses -y 0 to disable string truncation and FOR JSON AUTO to return unpadded JSON from SQL Server.
Controlled Writes & Previews
sqlcmd -S localhost -U sa -b -i migrations/001_init.sql
Runs a reviewed .sql file non-interactively and aborts with a non-zero exit code on any SQL batch error (-b).
Strengths for Agents
- + Pure Go binary (
go-sqlcmd) eliminates legacy ODBC driver installation pain. - +
-y 0+ T-SQLFOR JSONyields untruncated JSON directly from SQL Server. - +
-bguarantees non-zero exit codes on T-SQL errors.
Caveats & Pitfalls
- ! No native CLI
--jsonserializer (-Fsupportsvertical, notjson). - ! No client-side read-only flag; mutating SQL executes immediately unless restricted by DB user permissions.