且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SSMS中执行一组.SQL文件?

更新时间:2023-02-07 07:38:05

虽然SQLCMD.exe是***的方法,但SSMS还具有SQLCMD模式,您可以在其中执行SQLCMD脚本.要启用此模式,请在菜单栏中单击查询,然后选择 SQLCMD模式.

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.

:r filename.sql"命令是用于导入和执行sql脚本文件的SQLCMD脚本命令.您知道您处于SQLCMD模式,因为任何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.

:setvar path "c:\Path_to_scripts\"
:r $(path)\file1.sql
:r $(path)\file2.sql