How can I automate process of running all SQL scripts from given folder ?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
You can run an SQL script file with the sqlcmd command line tool that comes with SQL Server. The syntax is like this:
So basically, you just need to find all files in your folder, loop through them and execute sqlcmd for each one, like shown above.
I have created the following script for one of my projects:
I use this to recreate my database and start with a fresh database everyday. Mind you that it will execute the files in alfabetical order!
You can also use powershell to execute scripts in a given folder. http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/30/Executing-all-.SQL-files-in-a-directory-with-Powershell.aspx Jay
Write a Windows script, use the FOR construct to loop through your files and use the SQLCMD utility to execute each file.