Selecting databases to run scripts on in SQL Multi Select

When you add a server to a query group in SQL Multi Select, you can choose whether your scripts need to be ran on all the databases on that server, or just the database you’re connected to, or a specific set of databases.

The first option is an easy way to always run your queries on all your databases on a server.  Even when you add new databases to a server, your queries will still run on those databases.  When you need finer control over which databases to run your queries on, the third option comes in handy.

Let’s say you have a PostgreSQL server, and you set up the connection settings like this:

When you add this server to a group, you will need to specify on which databases your queries should run on.  If you want to run your queries on all databases on that server, just select the run scripts on all databases option.

Likewise, If you want to run your scripts only on the connected database, select the run scripts on connected database only option.

What if you need to specify a set of database names explicitly?  Just select the regular expressions filter option and list down the databases you want to include e.g. say you want to run your scripts only for the databases starting with the prefix database followed by the digits 0 to 6, and also databases starting with the prefix prod.

Or if you need to exclude a specific database, use the exclude filter e.g. say you want to exclude databases with the prefix dev.

This being a regular expression filter, you can easily include or exclude databases matching a string pattern e.g. say you want to include databases with the prefix prod, but not if the prefix is followed by the numbers 0 to 9.

 

Leave a Reply

Your email address will not be published. Required fields are marked *