April 12, 2010 at 1:26 pm
I have about 14 .SQL files that I would like to run in sequence against each database I create.
Anyone have an idea how to do this?
I would like to do something like the following:
???? setup.sql
???? setup2.sql
???? main.sql
???? next.sql
Thanks,
Mike
April 12, 2010 at 2:07 pm
It seems like SQLCMD or Powershell would work just fine for something like this. And really whichever you prefer, it should not make a difference.
Within SQLCMD you should be able to do something like (assumes scripts are located at c::
:connect server\instance
Use dbname
:r c:\setup.sql
[!!:]GO
:r c:\setup2.sql
[!!:]GO
:r c:\main.sql
[!!:]GO
:r c:ext.sql
If you are in powershell here is a link that shows you how to execute SQL containted in a file and it is very easy to use
http://serialseb.blogspot.com/2007/09/executing-sql-scripts-from-powershell.html
You could also do this via SSIS, if that is a tool you are more comfortable with and loop through the servers/sql files. Good luck.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply