How do I get the Query Timing with sqlcmd?

by Evan Carroll   Last Updated May 23, 2017 04:06 AM

Running SQL Server 2017, using the interactive REPL client sqlcmd how do I get the time for Query Execution?

You can sp_BlitzErik showing this in his answer here,

SQL Server Execution Times:
  CPU time = 1859 ms,  elapsed time = 321 ms.

Answers 1

I'm not sure you can.. yet (or at all, ever). However you can use time with -Q to get a rough approximation (less the connect/auth/teardown time)

time sqlcmd    \
  -S localhost \
  -U SA        \
  -P 'mypass'  \
  -d tempdb    \
  -Q "SELECT 1 AS 'myQuery';"


(1 rows affected)

real    0m0.038s
user    0m0.012s
sys 0m0.008s
Evan Carroll
Evan Carroll
May 23, 2017 03:53 AM

Related Questions

SQL Server Native Client ODBC Connection Fails

Updated March 01, 2017 14:06 PM

How do I bypass the typing of `GO` in `sqlcmd`?

Updated May 23, 2017 04:06 AM

Sql Server Configuration Manager

Updated June 03, 2017 05:06 AM