How can I list/review the sqlcmd history?

Mysql, Postgresql and sqlite write out to dot files: .mysql_history, .psql_history and .sqlite_history.

I'm looking for an equivalent (or approximation) when working with mssql/sql-server.


  • You need to read the data from the ldf file and that requires that you have recovery model set to full. More on this here: stackoverflow.com/questions/9767054/… – Daniel Björk Aug 12 '17 at 19:58
  • @DanielBjörk unfortunately this doesn't appear to be the sqlcmd client history but rather a history of executed transactions (part of which might be in the client history). Please correct me if I've misunderstood. – jimmont Aug 12 '17 at 20:13
  • oh my mistake. I read to fast. My bad, i stand corrected. – Daniel Björk Aug 12 '17 at 20:14
  • 1
    Are you looking for queries executed via -Q, or interactive mode, or from an input file? You are only concerned about your workstation, right, since those dot files would be per workstation / per login? – Solomon Rutzky Aug 12 '17 at 20:54
  • @SolomonRutzky interactive mode from the sqlcmd client. – jimmont Aug 13 '17 at 7:06

How can I list/review the sqlcmd history?

SQL Server and the SQLCMD utility do not, by default, track any of this. If you haven't yet setup customized logging then you won't be able to get any information.

SQLCMD is a command line utility and does not keep any history itself. You can setup extra command line logging outside of SQLCMD, but there is no switch or setting to turn on to default log any and all SQLCMD input or output.

The closest thing would be to create an extended events session or server audit that looks for connections through SQLCMD... However this would not be extremely worthwhile as application name and information can easily be spoofed.

In short - if you don't have anything setup, there is nothing. If you did set something up, there is no guarantee that you'll get everything.

If the question changes to "Who is executing what on my SQL Server?" this becomes an entirely different discussion.

| improve this answer | |
  • Is it possible to make this a feature request for sqlcmd? To output the history of input in sqlcmd (for the entire session) to the file .sqlcmd_history at the current working directory. – jimmont Nov 8 '17 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.