July 25, 2017 at 12:37 pm
Hi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.
Thanks,
July 25, 2017 at 12:50 pm
I don't have POSH script handy, but Powershell is the way to go IMO.
July 25, 2017 at 12:54 pm
sqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
SQLCMD would also do the job, I think.
Maybe use Excel to generate all of the SQL statements to be executed, rather than manually typing/cutting/pasting.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
July 25, 2017 at 1:37 pm
i run something like this that installs all my standard scripts on a given server.
you are really asking how can i add an outer loop to this, so ii can do it on multipel servers + databases, ro the same server plus miltipel databases, right?
#Set-ExecutionPolicy RemoteSigned
foreach ($f in Get-ChildItem -path "F:\StandardTakeOver\" -Filter CUS_*.sql | sort-object)
{
$out = "J:\StandardTakeOver\OUTPUT\" + $f.name.split(".")[0] + ".txt" ;
#invoke-sqlcmd -InputFile $f.fullname | format-table | out-file -filePath $out
#Flags:
# -S server\instancename
# -E = trusted connection
# -i input file
# -I Enable Quoted Identifier: critical fro stored proc creations
$f.name
sqlcmd -S "(local)" -E -I -i $f.fullname | format-table #| out-file -filePath $out
}
Lowell
July 25, 2017 at 3:16 pm
sqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
Are the databases all on the same machine?
--Jeff Moden
Change is inevitable... Change for the better is not.
July 28, 2017 at 6:54 pm
Did you get what you needed from the answers? Good question about the databases being on the same machine or instance too. If on a different machine you could even use SSMS, but I like the idea of having some output to look at with the powershell or even sqlcmd.
If this is a one time event, then you could even do it manually. If it is something that will happen with some frequency then go with powershell or the use of sqlcmd w/ a batch script. Have some examples of both if needed.
July 28, 2017 at 9:00 pm
Jeff Moden - Tuesday, July 25, 2017 3:16 PMsqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
Are the databases all on the same machine? They are on the same machine
July 28, 2017 at 9:58 pm
Am curious as to whether this a one time event or not. Also wonder how you are going to decide which 200 databases to run the scripts against. Will it be all if the user databases or just some of them. You may need a filter to select which ones to use.
I think the powershell script above is a good starting point.
July 28, 2017 at 10:17 pm
nerdCat - Friday, July 28, 2017 9:58 PMAm curious as to whether this a one time event or not. Also wonder how you are going to decide which 200 databases to run the scripts against. Will it be all if the user databases or just some of them. You may need a filter to select which ones to use.I think the powershell script above is a good starting point.
Hi,
Its a recurring event where product scripts are needed to be applied on multiple databases in multiple environments
July 28, 2017 at 10:44 pm
Cool. I am not home right now, but can help more if needed. Comments and questions above are all good.
You can drive this from a table, excel spreadsheet, etc.
The core of your script is going to be:
For each script (or database)
For each database (or script)
run script and send output to a file or concatenate to file
Powershell is pretty nifty. I've used spreadsheets and database tables to control items that would change.
I think mgmt is asking for a good thing with the output.
July 29, 2017 at 8:48 am
sqlguy80 - Friday, July 28, 2017 9:00 PMJeff Moden - Tuesday, July 25, 2017 3:16 PMsqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
Are the databases all on the same machine? They are on the same machine
Then you have no difficult hurdles. Write your scripts, write a wrapper to step through the databases (you might want to create a special table to exclude databases and, of course, you won't be scripting to any of the system databases) and run through the scripts for each database with some indication of success, failure, and which database its being executed on and write that output to a table in a common table using 3 part naming. Run the wrapper. No need for PowerShell or anything else outside of T-SQL.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 1, 2017 at 5:26 pm
sqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
I would suggest you to use central management server for ease the deployment across different servers and databases. You need to make sure the database name remains the same across the enterprise.
August 2, 2017 at 8:42 am
premkumardr - Tuesday, August 1, 2017 5:26 PMsqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
I would suggest you to use central management server for ease the deployment across different servers and databases. You need to make sure the database name remains the same across the enterprise.
That's a nice thought but what does it take to setup CMS to recognize the 200 databases that are differently named on the Same server that the OP has?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 2, 2017 at 10:17 am
Jeff Moden - Wednesday, August 2, 2017 8:42 AMpremkumardr - Tuesday, August 1, 2017 5:26 PMsqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
I would suggest you to use central management server for ease the deployment across different servers and databases. You need to make sure the database name remains the same across the enterprise.
That's a nice thought but what does it take to setup CMS to recognize the 200 databases that are differently named on the Same server that the OP has?
With some basic scripting and time to understand the xml, he could use a poor man's version of CMS by registering servers and grouping them using a .regsrvr file. Then the queries can be run for the entire group. Although, I'm not sure I would suggest that for all those databases.
August 2, 2017 at 5:57 pm
Luis Cazares - Wednesday, August 2, 2017 10:17 AMJeff Moden - Wednesday, August 2, 2017 8:42 AMpremkumardr - Tuesday, August 1, 2017 5:26 PMsqlguy80 - Tuesday, July 25, 2017 12:37 PMHi ,
Can any one suggest an efficient way where we can apply about 10 T-SQL scripts on about 200 databases and show the management a log file that the scripts were applied correctly?
We cannot use any third party tools.Thanks,
I would suggest you to use central management server for ease the deployment across different servers and databases. You need to make sure the database name remains the same across the enterprise.
That's a nice thought but what does it take to setup CMS to recognize the 200 databases that are differently named on the Same server that the OP has?
With some basic scripting and time to understand the xml, he could use a poor man's version of CMS by registering servers and grouping them using a .regsrvr file. Then the queries can be run for the entire group. Although, I'm not sure I would suggest that for all those databases.
True enough but that sounds like work. Just create a script in the form of some dynamic SQL and loop through the databases with a USE command.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 20 total)
You must be logged in to reply to this topic. Login to reply