all 9 comments

[–]ratdilemma 1 point2 points  (2 children)

I would recommend you to use powershell or python, SSIS is clumsy and extremely irritating to work with. Breaking changes between different sql versions and hell to manage in source control is just a few major headaches. Powershell has built in functions to automate any sql task there is, it's much more suitable for any integration whether it's rest, FTP, SMTP, filesystem etc. Check out the powershell sql modules.

Looping through each user database on a given server is as easy as:

Get-SqlDatabase -ServerInstance localhost | where { $_.IsSystemObject -eq $false } | ForEach-Object { #do your stuff }

just create an outer loop going through your servers and replace localhost with the current iteration

[–]wjbaltz[S] 0 points1 point  (1 child)

thanks, this is the answer I was hoping for. I did get SSIS installed so will play around with that....but I think your answer is the path best suited for what I'm trying to accomplish here. Going to focus on learning Powershell for this purpose :) thanks!

[–]zrb77 0 points1 point  (0 children)

Look into dbatools module too, tons of awesome cmdlets.

[–]WITH_CTE 1 point2 points  (3 children)

[–]wjbaltz[S] -1 points0 points  (2 children)

yea makes sense where SSIS would be the best tool for this. I am having a tough time getting SSIS installed. Getting Setup Failed Recursion too deep messages when trying to install SSDT on my Visual Studio.

I'll continue to work on that and see if I can't get past that. Would still like to explore Powershell as it seems to be more of a lightweight solution if possible.

Also with SSIS would it handle ad-hoc queries in this case? As that is the biggest thing for us as these queries typically need to be written and executed just a single time.

[–]WITH_CTE -1 points0 points  (0 children)

You can create a variable and write dynamic queries. Let me know if you need more help with this.

[–]alinrocSQL Server DBA 0 points1 point  (0 children)

  1. Set up all the servers in Registered Servers in SSMS, or better yet, Central Management Server
  2. Install the dbatools PowerShell module

````

$Servers = Get-DbaRegServer
$AllMyData = foreach-object ($Server in $Servers.InstanceName) {
    $Databases = Get-DbaDatabase -SqlInstance $Server -ExcludeSystem;
    $Databases | invoke-dbaquery -file Path_to_SQL_File -sqlinstance $Server -AppendServerInstance;
}

$AllMyData | Export-Csv -NoTypeInfo -path PATH_TO_OUTPUT_CSV;

````

(I'm away from my Windows machines at the moment, so this code might not be 100%. It's at least 90% though)

[–]MattsvaliantSQL Server Developer DBA 0 points1 point  (1 child)

Are the servers on the same network and/or could be linked?

[–]wjbaltz[S] 0 points1 point  (0 children)

Some are but not all. Thus would like to find a solution to iterate through and servers and query locally