如何在命令提示符 (CMD) 中执行 SQL 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20965846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:38:47  来源:igfitidea点击:

how to execute SQL statements in command prompt (CMD)

sqlsql-servercmd

提问by Dhanish Jose

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

如何在命令提示符 (CMD) 中执行 SQL 语句,

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

我在 Windows 8 操作系统中使用 SQL Server 2012。

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

我试过 sqlplus 和 sqlcmd,两者都给出错误“

enter image description here

在此处输入图片说明

Thanks in advance.

提前致谢。

回答by Lingasamy Sakthivel

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

您正在寻找的sqlcmd实用程序可让您在命令提示符下输入 Transact-SQL 语句、系统过程和脚本文件

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

Refer this

参考这个

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

编辑:OP说该sqlcmd.exe文件在安装路径中可用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\Binnand execute sqlcmdor add the sqlcmdpath (C:\Program Files\Microsoft SQL Server\110\Tools\Binn)to system PATH

您正在执行C:\Users>make path toC:\Program Files\Microsoft SQL Server\110\Tools\Binn并执行sqlcmd或将sqlcmd路径添加(C:\Program Files\Microsoft SQL Server\110\Tools\Binn)到系统PATH