Suppose I am h开发者_如何学Pythonaving 100 sql files and I need to execute all the files one by one in sequence. Is there any approach to do this with out executing the scripts manually?
You can write a bat file to execute them using sqlcmd Utility
Write a shell script or similar to run them sequentially.
We've had great success with the SQL Deploy tool by SSW Australia.
It's not free - but worth every penny, and saves you so much time, it pays for itself in no time at all!
(I have no affiliation with SSW Australia other than being a happy user of SQL Deploy)
- Pipe the
dir /b > foo.txt
output to a file - Add sqlcmd at the start of each line etc using a decent text editor like notepad++
You can use PowerShell to do this. The following blog post describes such a script. As part of the foreach a pipe is used to sort the files in the manner that you want to process them. In this example it is being sorted by descending alphabetical file name, but you can also do it by other attributes, such as the date the file was created.
Also the following blog post describes how to run all the .sql files in a directory like the above linked post, but without the use of PowerShell
Assuming your files are named something like this:
001_my_script.sql
002_another_script.sql
003_foo_script.sql
004_bar_script.sql
You can do the following at the command line:
copy *.sql /a my_big_script.sql
And then run the resulting file as one script (via sqlcmd or Management Studio).
精彩评论