How to execute SQL scripts against multiple SQL databases at the same time

ApexSQL Build is a SQL database update and build deployment tool, which includes a special feature for executing multiple SQL scripts against multiple SQL databases in a few simple steps.

Run ApexSQL Build and choose the Execute scripts on multiple databases:

Choose the Execute scripts on multiple databases option

This will open the Execute window in which Deployment database list can be defined, SQL scripts can be added, and the Execute button will run those SQL scripts against the databases in the list. After scripts are executed, the results can be examined in the preview pane in the middle of the Execute window:

Adding SQL scripts to be executed is simple by using the left pane toolbar, which allows adding/removing scripts as well as editing a specific SQL script directly from the preview pane. Additionally, the script execution order can be changed by using the Move up/Move down command, which is especially useful if a certain SQL script needs to be executed before another:

Adding SQL scripts to be executed

The organized SQL script list can be saved and re-used if there is a need for repeatable sessions. Adding databases is as simple as adding scripts – just click the Edit database deployment list button on the right side of the Execute window:

Click the Edit database deployment list button

This will open the Edit Database Deployment List window:

Deployment lists can be saved under custom names allowing the creation of multiple deployment scenarios or even grouping SQL databases under different lists according to specific deployment needs.

Another useful option is controlling a deployment process in case of encountered errors. It is possible to predefine courses of action in case that an error appear during deployment. It is a simple but handy option that helps control the process. This option is located on the main toolbar and offers several On error options:

The final step is to simply run the process using the Execute button from the main toolbar. SQL scripts will be executed in a predefined order against selected SQL databases. The results (or errors, if any) will be displayed in the preview pane:

The results are displayed in the preview pane

The main advantage of using this feature is reflected in its simplicity and multiple functionalities: it can save time while allowing complete control over the execution of multiple scripts against multiple SQL databases.

March 12, 2015