SQLCMD History – How to Access and Use

sql serversqlcmd

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.

Thanks.

Best Answer

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.