Run sql query files | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Run sql query files

Hi all, I wrote lot of stored procedures and views in query files (.sql) in my test server. While copying the same into the live server i forced to load one by one queries and press F5 to apply all those. Can anyone advice any other way so that I can apply all procedures thru one file ( like running a batch file which will load stored procedures one by one ) Thanks and Regards
Put them in a single file and seperate each procedure by GO and run as a whole Madhivanan Failing to plan is Planning to fail

If you have GO in each of your procedure scripts you can use the following code in a batch file to combine the scripts REM this will add all files with the .sql extension in the current folder to a file called scripts.txt
type *.sql > scripts.txt
REM NB don’t call it scripts.sql…
Note that you may need to sort out the dependencies as some procedures may call others, these will obviously need to be created after the procedures they call. I think that you can get away with keeping on running the create procedure script until the errors go away. However you may get dependency problems if your script drops procedures before the creation. Regards, Robert.