如何在SSMS中执行一组.SQL文件? [英] How can I execute a set of .SQL files from within SSMS?

查看:851
本文介绍了如何在SSMS中执行一组.SQL文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SQL Server Management Studio中执行一组.SQL文件(每个文件都会进行一些数据转换)?

How could I execute a set of .SQL files (each does some data transformations) from within SQL Server Management Studio?

还有什么其他方法可以批量执行.SQL文件?

What other alternative are there for executing .SQL files in batch?

推荐答案

虽然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

这篇关于如何在SSMS中执行一组.SQL文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆