Installing SQLCMD
2October 19, 2016 by Kenneth Fisher
For anyone who wasn’t aware SQLCMD is a command line tool for running T-SQL statements and scripts. Before anyone says anything I want to point out that yes, I realize that you can use Powershell instead. Of course not all of us know Powershell all that well and most of us do know T-SQL. Until that changes (and I expect it will) SQLCMD (or some form of it) will be around.
What are some common uses for SQLCMD?
- Run scripts on remote servers.
SQLCMD can easily be used to run a script or stored procedure on a remote SQL Server. Combining this with a bat file (yes, again older technology) and an Enterprise scheduler (because not all of us use SQL Server Agent) can be a very powerful way to run T-SQL. - Connecting to the DAC
The DAC (dedicated admin connection) is vitally important when you have problems with your SQL Server. It has its own dedicated resources and can be used even when no other connections may be able to do anything. SQLCMD is a light weight way of connecting and fixing your server.
SQLCMD is installed with SSMS and with the database engine. This means it’s going to be installed on the server where your instance is located and probably your workstation as well. However every now and again you want it installed on a machine where no SQL components are installed. Say an application server. It’s not overly difficult fortunately. You just download and install the Command Line Utilities for SQL Server.
Hi Kenneth,
Hope you are doing fine! I need help in setting up the sqlcmd.exe in windows 2016 server. I have setup the sqlps module and sqlserver modules. However I am getting the below error while executing the remote script using powershell
‘”sqlcmd -E -S “servername” -b -Q “sqlcmd’ is not recognized as an internal or external command,
operable program or batch file.
13:07:49 – Exit Code 1
Can you suggest me a fix or troubleshooting steps to resolve this issue.
regards,
Deepak katika
Generally I would recommend posting questions like these on a forum. I like dba.stackexchange.com and sqlservercentral.com. That said, I would check where sqlcmd is installed and where you are running it from. It may just not be in the path correctly.