@@ -122,6 +122,9 @@ sscli sql "SELECT TOP 5 * FROM Users" |
122 | 122 | sscli "SELECT COUNT(*) FROM Users" # Top-level shorthand for inline SQL |
123 | 123 | sscli sql --file [path/to/file] # Run long queries, execute bulk statements |
124 | 124 | cat patch.sql | sscli sql --stdin # Pipe a script on stdin |
| 125 | +sscli --format tsv --no-headers "SELECT COUNT_BIG(*) FROM Users" |
| 126 | +sscli --trust-cert true --quiet-tls-warning "SELECT 1" |
| 127 | +sscli --password-env SQL_PASSWORD status # Avoid putting passwords on the command line |
125 | 128 | sscli update # Check for new releases (alias: sscli upgrade) |
126 | 129 | ``` |
127 | 130 |
|
@@ -271,6 +274,12 @@ cp config.example.yaml .sql-server/config.yaml |
271 | 274 |
|
272 | 275 | Run `sscli config` to confirm which config file is being used and what values are in effect. |
273 | 276 |
|
| 277 | +A profile named by `--profile`, `SQL_SERVER_PROFILE` or `defaultProfile` must exist: |
| 278 | +an unknown name is an error that lists the profiles the config defines, rather |
| 279 | +than a silent fall back to `localhost`. When no config file, `--server` or |
| 280 | +`SQL_SERVER`/`SSCLI_URL` names a server, commands warn on stderr that they are |
| 281 | +using the built-in `localhost:1433/master` default. |
| 282 | + |
274 | 283 | ### Example `config.yaml` |
275 | 284 |
|
276 | 285 | ```yaml |
@@ -300,7 +309,7 @@ load `.env` from the current working directory. |
300 | 309 | | ------------------------ | --------------------------------------------------------------------------------------------------------- | |
301 | 310 | | Config path | `SQL_SERVER_CONFIG`, `SQLSERVER_CONFIG` | |
302 | 311 | | Profile | `SQL_SERVER_PROFILE`, `SQLSERVER_PROFILE` | |
303 | | -| Connection URL | `DATABASE_URL`, `DB_URL`, `SQLSERVER_URL` | |
| 312 | +| Connection URL | `SSCLI_URL`, `DATABASE_URL`, `DB_URL`, `SQLSERVER_URL` | |
304 | 313 | | Server | `SQL_SERVER`, `SQLSERVER_HOST`, `DB_HOST`, `MSSQL_HOST` | |
305 | 314 | | Port | `SQL_PORT`, `SQLSERVER_PORT`, `DB_PORT`, `MSSQL_PORT` | |
306 | 315 | | Database | `SQL_DATABASE`, `SQLSERVER_DB`, `DATABASE`, `DB_NAME`, `MSSQL_DATABASE` | |
@@ -319,6 +328,9 @@ load `.env` from the current working directory. |
319 | 328 | | Password | `SQLCMDPASSWORD` | |
320 | 329 | | Database | `SQLCMDDBNAME` | |
321 | 330 |
|
| 331 | +Connection URL query options include `trustServerCertificate=true|false`, |
| 332 | +`encrypt=true|false`, and `timeoutMs=<milliseconds>`. |
| 333 | + |
322 | 334 | ## Commands |
323 | 335 |
|
324 | 336 | **Core** (shown in `--help`): |
@@ -344,6 +356,9 @@ load `.env` from the current working directory. |
344 | 356 | | `query-stats` | Top cached queries by resource usage | |
345 | 357 | | `backups` | Recent backup history | |
346 | 358 | | `compare` | Schema drift detection between two connections | |
| 359 | +| `compare-counts` | Row-count validation across databases | |
| 360 | +| `health` | Constraint, trigger, and identity summaries | |
| 361 | +| `admin` | SQL Server maintenance SQL, backup, and DBCC (see [admin](#admin-maintenance-sql)) | |
347 | 362 | | `integrations` | Install agent skills/extensions | |
348 | 363 |
|
349 | 364 | Note: `sscli sessions` filters by client host name using `--client-host`. `--host` is reserved as an alias for `--server`. |
@@ -356,8 +371,19 @@ Note: `sscli sessions` filters by client host name using `--client-host`. `--hos |
356 | 371 | | Piped / non-TTY | Markdown tables | |
357 | 372 | | `--json` flag | Stable JSON (v1 contract) | |
358 | 373 | | `--csv <file>` | CSV export | |
| 374 | +| `--format tsv` | Raw TSV rows | |
| 375 | +| `--format csv` | Raw CSV rows | |
| 376 | +| `--format jsonl` | One JSON object per row | |
359 | 377 |
|
360 | 378 | JSON output emits exactly one object to stdout. Errors go to stderr. |
| 379 | +`sql` and `admin sql` print an `Execution` summary table when a script returns no |
| 380 | +result sets, so a statement that succeeded silently is still visible. See |
| 381 | +[admin](#admin-maintenance-sql). |
| 382 | +Raw row formats keep stdout data-only; target banners, progress, warnings, and |
| 383 | +errors go to stderr. Use `--no-headers` for headerless TSV/CSV evidence files |
| 384 | +and `--output <path|->` to write raw row output. |
| 385 | +Use `--quiet-tls-warning` when `--trust-cert true` is intentional and verbose |
| 386 | +logging would otherwise print Tiberius' certificate-validation warning. |
361 | 387 |
|
362 | 388 | ## Safety |
363 | 389 |
|
@@ -384,13 +410,108 @@ Each command returns a stable top-level object: |
384 | 410 | | `table-data` | `{ table, columns, rows, total, offset, limit, hasMore, nextOffset }` | |
385 | 411 | | `sql` | `{ success, batches, resultSets, csvPaths? }` | |
386 | 412 | | `compare` | `{ modules, indexes, constraints, tables }` when `--summary`; `{ source, target }` snapshots with full metadata when `--json` without `--summary` | |
| 413 | +| `compare-counts` | `{ sourceDb, targetDb, counts }` | |
| 414 | +| `health` | `{ kind, checks }` | |
| 415 | +| `admin sql` | `{ status, error, partialEffectPossible, elapsedMs, batchCount, batchesSucceeded, batches, resultSetCount, rowsReturned, resultSets, verify }` | |
| 416 | + |
| 417 | +`config --json` never emits plaintext passwords by default. It reports |
| 418 | +`passwordSet`, `passwordSource`, and `passwordEnv` metadata instead. |
387 | 419 |
|
388 | 420 | Errors (stderr): |
389 | 421 |
|
390 | 422 | ```json |
391 | 423 | { "error": { "message": "...", "kind": "Config|Connection|Query|Internal" } } |
392 | 424 | ``` |
393 | 425 |
|
| 426 | +## Scripts and `GO` batches |
| 427 | + |
| 428 | +`sql --file`, `sql --stdin` and `admin sql` run scripts the way `sqlcmd -b` does: |
| 429 | + |
| 430 | +- A line holding only `GO` (any case, optionally `GO n` to repeat the batch, or a |
| 431 | + trailing `--` comment) ends a batch. `GO` inside a string, bracketed |
| 432 | + identifier or comment is left alone. |
| 433 | +- Every batch runs in order on one session. A transaction opened in one batch |
| 434 | + can be committed in a later one, and `SET` options, `USE` and `#temp` tables |
| 435 | + carry over, as they do in `sqlcmd`. |
| 436 | +- The first failing batch stops the script with a non-zero exit, and the error |
| 437 | + names the batch (`Batch 3 of 5 failed: ...`). The session then closes, so the |
| 438 | + server rolls back a transaction the script left open. `sql --continue-on-error` |
| 439 | + keeps going instead. |
| 440 | + |
| 441 | +A batch that uses `--param` values runs through `sp_executesql`, so a |
| 442 | +transaction cannot stay open across that batch. Batches that use no parameter |
| 443 | +are unaffected. |
| 444 | + |
| 445 | +`sql` runs any statement, writes included. The `sql` banner on stderr shows the |
| 446 | +target, profile and config file (`Target: host:port/db (profile dev, |
| 447 | +/path/.sql-server/config.yaml)`), so check it before you run a write script. |
| 448 | + |
| 449 | +## admin (maintenance SQL) |
| 450 | + |
| 451 | +`admin sql` runs full-capability maintenance SQL. `GO` splits the script into |
| 452 | +batches, which run in order on one connection and stop at the first failure. |
| 453 | + |
| 454 | +### Execution summary |
| 455 | + |
| 456 | +Maintenance statements usually return no rows, so `admin sql` and `sql` always |
| 457 | +print an `Execution` summary. A successful `DROP DATABASE` is therefore visibly |
| 458 | +different from a command that never ran: |
| 459 | + |
| 460 | +``` |
| 461 | +$ sscli admin sql "DROP DATABASE IF EXISTS [WDM_VERIFY];" |
| 462 | +Target: localhost:1433/master |
| 463 | +| Execution | Value | |
| 464 | +|--------------|------------------| |
| 465 | +| Status | ok | |
| 466 | +| Batches | 1 of 1 succeeded | |
| 467 | +| ResultSets | 0 | |
| 468 | +| RowsReturned | 0 | |
| 469 | +| ElapsedMs | 11 | |
| 470 | +``` |
| 471 | + |
| 472 | +Multi-batch scripts also print a per-batch table, so a run that stops halfway |
| 473 | +shows which batches already applied. That matters when an earlier batch leaves |
| 474 | +state behind, such as `ALTER DATABASE ... SET SINGLE_USER` followed by a |
| 475 | +`DROP DATABASE` that fails. Failures exit non-zero with the server message on |
| 476 | +stderr. |
| 477 | + |
| 478 | +A batch is not all-or-nothing. It holds every statement up to the next `GO`, and |
| 479 | +semicolon-separated statements before the failing one have already committed. So |
| 480 | +`Batches 0 of 1 succeeded` means the batch did not complete, not that nothing |
| 481 | +happened, and the summary says so: |
| 482 | + |
| 483 | +``` |
| 484 | +| Status | failed | |
| 485 | +| Batches | 0 of 1 succeeded | |
| 486 | +| FailedBatch | 1 (statements before the failure may have taken effect) | |
| 487 | +``` |
| 488 | + |
| 489 | +After any failed batch, read the current state back rather than assuming a |
| 490 | +rollback. In JSON, `partialEffectPossible` carries the same warning. |
| 491 | + |
| 492 | +### Verified maintenance |
| 493 | + |
| 494 | +`Status ok` proves the statement executed, not that it changed anything: |
| 495 | +`DROP DATABASE IF EXISTS` reports success even as a no-op. Use `--verify` to run |
| 496 | +a read-back on the same connection and `--expect-rows` to assert its row count. |
| 497 | +A mismatch prints the summary, then exits non-zero. |
| 498 | + |
| 499 | +```bash |
| 500 | +# Drop a database and prove it is gone |
| 501 | +sscli admin sql "DROP DATABASE [WDM_VERIFY];" \ |
| 502 | + --verify "SELECT name FROM sys.databases WHERE name = 'WDM_VERIFY'" \ |
| 503 | + --expect-rows 0 |
| 504 | +
|
| 505 | +# Prove a database was created |
| 506 | +sscli admin sql "CREATE DATABASE [WDM_VERIFY];" \ |
| 507 | + --verify "SELECT name FROM sys.databases WHERE name = 'WDM_VERIFY'" \ |
| 508 | + --expect-rows 1 |
| 509 | +``` |
| 510 | + |
| 511 | +`--verify` without `--expect-rows` reports the read-back rows without asserting |
| 512 | +them. The read-back is skipped when a batch fails, because it would describe a |
| 513 | +half-applied script. |
| 514 | + |
394 | 515 | ## compare (schema drift) |
395 | 516 |
|
396 | 517 | Detects drift between two profiles or explicit connection strings. |
|