SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Exec scripts in a group of databases

By William Talada,

If you generally execute your scripts against a group of databases, create a template like the one above and drag it to the top of your script in the script window. Hit execute three times to cycle through them to apply your script to all databases in the group.

Make the group circular if you want to be able to start with any database in the group.
Make it linear if you always want to execute changes to older or newer versions in a progressive manner.

The first three lines above make it jump into the group from any database. You can remove those lines for more secure control.

If you implement a circular list, start with the last database in your group so it will be changed to the first before executing your script, if order is important to you.

Sometimes it is little tricks like this that make the workday so much better. F.Y.I. a "USE" statement may not be put in a stored procedure, trigger, or function.

Total article views: 1016 | Views in the last 30 days: 2
Related Articles

Backup databases in an Availability Group

Use this script to backup databases based on their role in an availability group


URGENT: Error executing scripts......

URGENT: Error executing scripts......


Connditional executing of script

Connditional executing of script


SSIS as an Execution Engine for Multiple Sql scripts

Learn how you can execute multiple scripts in a restrictive database environment that doesn't allow ...