How could I execute a set of .SQL files (each does some data transformations) from within SQL Server Management Studio?
如何从SQL Server Management Studio中执行一组.SQL文件(每个文件都执行一些数据转换)?
What other alternative are there for executing .SQL files in batch?
在批处理中执行.SQL文件还有什么其他选择?
2 个解决方案
#1
57
While SQLCMD.exe is the best way, SSMS also has a SQLCMD mode where you can execute a SQLCMD script. To enable this mode click Query in menu bar then select SQLCMD Mode.
而SQLCMD。exe是最好的方法,SSMS还具有SQLCMD模式,您可以在这种模式下执行SQLCMD脚本。要启用此模式,请单击菜单栏中的Query,然后选择SQLCMD模式。
The ":r filename.sql" command is the SQLCMD script command to import and execute a sql script file. You know you are in SQLCMD mode because any lines that are SQLCMD script commands will appear with colored (gray I think) background.
”:r文件名。sql“命令是SQLCMD脚本命令,用于导入和执行sql脚本文件。您知道您处于SQLCMD模式中,因为任何带有SQLCMD脚本命令的行都将以彩色(灰色我认为)的背景出现。
:setvar path "c:\Path_to_scripts\"
:r $(path)\file1.sql
:r $(path)\file2.sql
#2
18
Use SqlCmd.exe.
使用SqlCmd.exe。
For example:
例如:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
or to save output to a file:
或将输出保存到文件:
sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt
#1
57
While SQLCMD.exe is the best way, SSMS also has a SQLCMD mode where you can execute a SQLCMD script. To enable this mode click Query in menu bar then select SQLCMD Mode.
而SQLCMD。exe是最好的方法,SSMS还具有SQLCMD模式,您可以在这种模式下执行SQLCMD脚本。要启用此模式,请单击菜单栏中的Query,然后选择SQLCMD模式。
The ":r filename.sql" command is the SQLCMD script command to import and execute a sql script file. You know you are in SQLCMD mode because any lines that are SQLCMD script commands will appear with colored (gray I think) background.
”:r文件名。sql“命令是SQLCMD脚本命令,用于导入和执行sql脚本文件。您知道您处于SQLCMD模式中,因为任何带有SQLCMD脚本命令的行都将以彩色(灰色我认为)的背景出现。
:setvar path "c:\Path_to_scripts\"
:r $(path)\file1.sql
:r $(path)\file2.sql
#2
18
Use SqlCmd.exe.
使用SqlCmd.exe。
For example:
例如:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
or to save output to a file:
或将输出保存到文件:
sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt