Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute a set of .SQL files from within SSMS?

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

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

like image 872
Even Mien Avatar asked May 08 '09 17:05

Even Mien


People also ask

How do I run multiple SQL files in SSMS?

From there, CTRL+V into an SSMS window. It works with multiple files too. Select two or more files in Explorer, right-click any of the highlighted files, and select "Copy as path". Repeat steps in SSMS.

How do I run a .SQL File in SQL Server Management Studio?

Open SQL Server Management Studio > File > Open > File > Choose your . sql file (the one that contains your script) > Press Open > the file will be opened within SQL Server Management Studio, Now all what you need to do is to press Execute button.


1 Answers

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.

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 
like image 67
DCNYAM Avatar answered Oct 07 '22 11:10

DCNYAM