Sql Server issue - 'sqlcmd' is not recognized as an internal or external command

+1 vote
21,782 views
asked Aug 7, 2016 by Hitesh Garg (799 points)  

I have a bat file that runs some SQL commands for the SQL SERVER and currently I am using SQL SERVER 2012.
I basically runs commands in two steps, one to drop the existing schema and another to recreate the new schema.
Step one is completed successfully but during the execution of step two i.e. recreate schema part it gives the following error -

'sqlcmd' is not recognized as an internal or external command

What is the possible solution for this problem?

2 Answers

+1 vote
answered Aug 7, 2016 by Rahul Singh (682 points)  
selected Aug 7, 2016 by Hitesh Garg
 
Best answer

Let us assume that the SQL Server installation is done properly.
If the command prompt returns -

(name of the software) is not recognized as an internal or external
command, operable program or batch file.

this means that the file of software of command is not defined in the %PATH% environment variable.

With this latter it is possible to recall executable applications without defining their full path. Then, to solve this issue you can create an environment variable with the complete location and add it to the path:
On my system I have SQLCMD.exe at location C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn. Please find where it is in your system. To find simply go to SQL Server installation folder and search for sqlcmd.exe.

  1. Control Panel > System > Advanced > Environment Variables
  2. Add a new variable give it a name let say SQLSERVERSQLCMD and add path in the value i.e. C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn.
  3. Find another variable named PATH and add %SQLSERVERSQLCMD% at the end of it.

Hope this helps and solves your problem.

commented Aug 7, 2016 by Hitesh Garg (799 points)  
Thanks, that solves my problem.
+1 vote
answered Sep 9, 2016 by sksanjai (45 points)  

This error occurs when the exe or batch file is not found. To get rid out of this error just add the SQL Server path to system variables

...