Running SQL Server 2017, using the interactive REPL client
sqlcmd how do I get the time for Query Execution?
SQL Server Execution Times: CPU time = 1859 ms, elapsed time = 321 ms.
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
I agree with Joe's answer but want to mention about a built in switch which give you few more data point. You can do it with
Prints performance statistics for every result set. The following is an example of the format for performance statistics:
x = Number of transactions that are processed by SQL Server . t1 = Total time for all transactions. t2 = Average time for a single transaction. t3 = Average number of transactions per second.
All times are in milliseconds.
If the optional parameter 1 is specified, the output format of the statistics is in colon-separated format that can be imported easily into a spreadsheet or processed by a script. If the optional parameter is any value other than 1, an error is generated and sqlcmd exits.
By default this will add a footer to the query that looks like this,
Network packet size (bytes): 4096 1 xact[s]: Clock Time (ms.): total 1 avg 1.0 (1000.0 xacts per sec.)