Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 How to execute SQL scripts in batch

Author  Topic 

Starting Member

6 Posts

Posted - 2015-04-08 : 04:44:01
I have separate scripts for Creation of Tables, Stored Procedures, Views, Triggers in different .sql files.
I have to execute thses scripts in batch in different servers and different databases without opening SSMS.
All .sql files to be executed in single command.

Please suggest how to achieve?
Appreciate your help.



22859 Posts

Posted - 2015-04-08 : 04:50:21
We use a BATCH file and the command line program SQLCMD e.g. something like this

SQLCMD -d MyDatabaseName -i MyScriptName.SQL -o C:\MyPath\MyScriptName.OUT -b -l 300 -S . -E >>C:\MyPath\MyScriptName.LOG
Go to Top of Page

Master Smack Fu Yak Hacker

2179 Posts

Posted - 2015-04-09 : 01:39:34
For a bit of extra flexibility you can invoke SQLCMD from within Powershell. see example here:
Gives you the extra scripting options with Powershell

Jack Vamvas
Go to Top of Page

- Advertisement -