Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute SQL statements in command prompt (CMD) [closed]

how to execute SQL statements in command prompt (CMD),

I'm using SQL Server 2012 in windows 8 OS.

I have tried sqlplus and sqlcmd, both are giving error "

enter image description here

like image 548
Dhanish Jose Avatar asked Jan 07 '14 07:01

Dhanish Jose


People also ask

How do I close a SQL command line?

You can also terminate the session by issuing an EXIT statement or (under Unix) by typing Ctrl-D.

How do you check SQL Server is running or not using CMD?

Go to Start → Run, type cmd, and hit enter to open the command prompt. Step 2 -SQLCMD -S servername\instancename (where servernameb= the name of your server, and instancename is the name of the SQL instance). The prompt will change to 1→. Step 4 -At the 2→ prompt type go and hit enter.


1 Answers

You are looking for the sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt

sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName 
-Q "query"

Refer this

Edit: The OP said The sqlcmd.exe file is available in the installation path C:\Program Files\Microsoft SQL Server\110\Tools\Binn

You are executing with C:\Users> make the path to C:\Program Files\Microsoft SQL Server\110\Tools\Binn and execute sqlcmd or add the sqlcmd path (C:\Program Files\Microsoft SQL Server\110\Tools\Binn) to system PATH

like image 82
Linga Avatar answered Nov 15 '22 05:11

Linga