I have used a powershell script to do this before. I've included it here. The other answers about using proper tools is best, although I disagree with putting the objects in a common database for the problems you mentioned.
The script is powershell and uses windows authentication. It doesn't really do any error handling, but does have a bit that will test if the database is one of those that needs updating. Just feed it a list of SQL Instances, determine a unique table (or other query) to identify if it's one of your application databases and point it at a folder containing .sql files.
Some clarification on the script
$SQLInstanceList - This is the full path to a text file that contains all the SQL instances you want it to step over. One entry per line.
Server1
Server1\Instance1
Server2
$ScriptToRunDirectory - the directory that contains the sql files you want to run.
$Query - a query so that when it looks at a database it knows that it should run the queries against it. I put this step in because I assumed that not every database on every server is one of your application databases. For example, ReportServer, master, model, tempdb, other custom databases etc you would want to skip. I also assumed that there is at least one table that is common to all of your application databases. So when it steps over each database, it runs the above query, essentially checking to see if the specified table exists. If it does, it will run everything in the $ScriptToRunDirectory folder, otherwise it will skip it.
So the basic premise of the script is as follows:
* For each SQL Instance that is listed, connect
* For each database that is in the SQL instance:
* run $Query to determine if it's the correct database type
* If database is correct type then:
* for each .sql file in $SQLToRunDirectory
execute.
<#
Name: Execute Script against Servers
Author: Jonathan Fite
Created: 5/3/2017
Purpose: To execute sql scripts against a variety of servers.
This script will take a list of servers and instances and then iterate
over every database. It has a section where you can query for whether
a specific object exists. If it exists, it will execute all the scripts
in the specified directory.
$SQLInstanceList - The full path and name of a text file containing the names of
the instances to run against. One entry per line, Ex: MyServerName\MyInstanceName
$ScriptToRunDirectory - The full path to a directory containing the script file(s) that you want to use.
It doesn't do recursion, but will pick up any .sql file in the directory and run it agains thte server.
It does so in alphabetical order, so put numbers at the front of the scripts if execution sequence is important.
$Query - This should be a query that will be run to determine if the rest of the scripts should be run or not.
You should set it to return 0 if it's the wrong database and anything else if it's the right one.
The example below determines if the current database (remember the script is stepping over every database)
has the specified object. Remember to specify the schema.
#>
# Modify the below items to the necessary values.
$SQLInstanceList = "C:\Temp\SQLInstance.txt"
$ScriptToRunDirectory = "C:\Temp"
$Query = "SELECT ISNULL(OBJECT_ID('HumanResources.Department'), 0)"
# You shouldn't need to modify anything below this line.
################################################################################################
# For Each
ForEach ($Instance In Get-Content $SQLInstanceList)
{
Write-Host "Connecting to: " $Instance
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$SMO = new-object ('Microsoft.SqlServer.Management.Smo.Server') $Instance
ForEach ($Database In ($SMO.Databases))
{
Write-Host "Database: $($Database.Name)"
#Test to make sure that we want to run it against this database.
$Results = ($SMO.Databases[$Database.Name].ExecuteWithResults($Query)).Tables[0].Rows[0][0]
if($Results -ne 0)
{
Write-Host " Database Matched Criteria"
ForEach ($File In (Get-ChildItem -Path $ScriptToRunDirectory -Filter "*.sql") | Sort-Object $_.name)
{
Write-Host " - $($File.FullName)"
$Script = [System.IO.File]::ReadAllText($File.FullName)
Write-Host " " $File.name
$Database.ExecuteNonQuery($Script)
}
} else {
Write-Host " Database Skipped"
}
}
}