Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute SQL scripts in batch

Status
Not open for further replies.

balushanmugham

Programmer
Jun 16, 2012
6
0
0
IN
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.

Regards,
Bala
 
There are a couple of ways. Use a front end such as .NET, use SQLCMD which is the command line utility, PowerShell.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Choose whatever programming language you're familiar with, write a routine to retrieve all *.sql files from a directory and iterate over them to call into .NET SQLCommand, SQLCMD or corresponding powershell commands for executing a sql file.

You're looking for a single command for that, that's your only error. As a Programmer you develop these commands, they are called functions, maxbe also batch scripts and they iterate multiple single commands to make them availabel by a single function or batch name.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top