如何从SQL Server的命令行工具执行sql查询?

问题描述:

我是SQL Server中的新成员,有人可以帮助我从SQL Server中的命令行工具执行SQL查询吗?如何从SQL Server的命令行工具执行sql查询?

+4

的可能的复制[如何执行在命令提示(CMD)SQL语句](http://*.com/questions/20965846/how-to-execute-sql-statements-in-command-prompt -cmd) –

使用以下命令提示符查询以使用SQLCMD执行filename.sql。

SQLCMD -d <database-name> -U <User-name> -P <Password> -i filename.sql -o output.txt 

-d = Database Name 
-U = User Name 
-P = Password 
-i = Filename.sql 
-o = output.txt 
-E = Windows Authentication mode if you specify this need to skip -U & -P parameters.