Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

sqlcmd

$ sqlcmd Official High Risk
Microsoft · Database & Data · MIT · macos / linux / windows

sqlcmd (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.

FCRS-1.0 Score
77 /100
Good
Medium Confidence
Zero-Friction Install
brew install sqlcmd
CLI vs MCP Decision CLI Preferred vs MCP

Direct sqlcmd -Q execution with T-SQL FOR JSON and -b error exit codes avoids heavy multi-tool SQL MCP schemas.

Agent-Readiness Checklist

— JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 19 / 25

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 + -b provides non-interactive execution and error exit codes
  • No native --json flag; requires T-SQL FOR JSON with -y 0
Trust & Safety 18 / 25

Supports SQLCMDPASSWORD and Entra ID auth, though has no client-side --readonly or --dry-run guard against DROP/DELETE queries.

  • SQLCMDPASSWORD avoids exposing secrets in process args
  • No client-side read-only SQL guard
Setup & Portability 13 / 15

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
Utility & Efficiency 12 / 15

Full T-SQL access, sqlcmd create mssql local container helpers, and variable substitution (-v).

  • Supports scripts (-i), variables (-v), and local container bootstrap
Maintenance & Lineage 8 / 10

Official Microsoft repository (microsoft/go-sqlcmd) under MIT license.

  • First-party Microsoft Go rewrite
Docs & Verifiability 7 / 10

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

Auth Modes
Env API Key OAuth Browser Config File
Credential Storage

Supports SQLCMDPASSWORD env var, Entra ID (--authentication-method), Windows integrated auth (-E), and local context config in ~/.sqlcmd/.

Side Effects
Read-Only Remote Write Destructive
Cost & Quotas

MIT open-source CLI; free (requires access to a SQL Server or billable Azure SQL instance).

Copyable Guardrail for CLAUDE.md / AGENTS.md
# 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

Run a read-only query formatted via T-SQL FOR JSON
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

Execute a parameterized SQL script and exit on error
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-SQL FOR JSON yields untruncated JSON directly from SQL Server.
  • + -b guarantees non-zero exit codes on T-SQL errors.

Caveats & Pitfalls

  • ! No native CLI --json serializer (-F supports vertical, not json).
  • ! No client-side read-only flag; mutating SQL executes immediately unless restricted by DB user permissions.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI