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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 How to execute SQL scripts in batch
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

6 Posts

Posted - 04/08/2015 :  04:44:01  Show Profile  Reply with Quote
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.



United Kingdom
22859 Posts

Posted - 04/08/2015 :  04:50:21  Show Profile  Reply with Quote
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

Edited by - Kristen on 04/08/2015 04:51:36
Go to Top of Page

Flowing Fount of Yak Knowledge

United Kingdom
2179 Posts

Posted - 04/09/2015 :  01:39:34  Show Profile  Visit jackv's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000