r/SQL • u/Pawelm_rot • Apr 23 '26
Discussion How do you handle running SQL scripts across many servers/databases?
I’m curious how others deal with this workflow.
In my job we have many SQL Server instances with multiple environments (dev/test/prod copies). Almost every day we need to update database structures or run batches of scripts across dozens of databases on several servers.
Doing it manually in SSMS was slow and error‑prone, so a few years ago I built an internal tool to speed things up. It lets us load servers, fetch databases, select targets, run scripts in sequence or in parallel, see per‑database success/failure, timeline, dry‑run, etc.
I’m not linking anything here — I’m more interested in the concept than promoting a tool.
My questions to you:
- How do you handle multi‑server / multi‑database updates?
- Do you use custom tools, SSMS, scripts, CI/CD, something else?
- Would features like parallel execution, dry‑run, or execution timeline be useful in your workflow?
- What would be a “must have” vs “nice to have”?
I’d like to understand how others approach this problem and what matters most in real‑world scenarios.
9
u/VladDBA SQL Server DBA Apr 23 '26
It depends on what you need, but just for running scripts I'd go with CMS, if it requires more granular control, logging, error handling, and integration with other services I'd use PowerShell and dbatools
2
u/SootSpriteHut Apr 23 '26
I'm not an expert on this stuff yet but at my company they handle data model changes with migrations tied to our PR system.
Data transfers themselves between instances are harder. I remember when I was an an azure shop it was easy to link databases across servers but I'm MySQL now so I do it by hand and have made bash scripts but it's a PITA.
I'd like to be regularly updating staging with prod data but it's just not as high a priority with everything else I'm doing so I haven't quite figured it out yet.
3
u/Sea_Basil_6501 Apr 23 '26
You can use SQL Server Management Studio and connect to several servers with one single query editor window. Then run your query.
1
u/Pawelm_rot Apr 28 '26
Thanks everyone for sharing your approaches — it was really helpful to see how others think about this workflow.
For my part, I ended up building a setup where I keep all servers in a configuration file, grouped by environments or categories. For each server I fetch the list of databases once and store it, so I can work with a simple tree where I select whatever targets I need.
From there I can run either a single script or a whole ordered package of scripts. Execution can be parallel across servers (up to 8 at a time with queueing) or sequential, and I also have a dry‑run mode. After execution I get a summary of which databases succeeded or failed, which scripts failed, timings per script, total duration, and a timeline view that I can filter or export. I can also save/load sessions so I don’t have to re‑fetch everything during repetitive tasks.
There are more details, but that’s the general idea. It’s been used internally for years, so the workflow is fairly battle‑tested. I’m planning to add things like variable handling and some light automation.
Thanks again for the insights — it’s interesting to see how different teams approach multi‑server updates.
2
u/pitifulchaity Apr 23 '26
For that kind of workflow, I care less about where I click Run and more about how much control I have before it runs. Once you’re touching a lot of servers, dry-run, logging, and being able to review changes cleanly matter more than the editor itself. We’ve used dbForge more on the review/check side and kept the execution flow separate.
1
u/Subject_Fix2471 Apr 23 '26
This might be useless to you, but when I've worked with postgres it's typically been with alembic for schema changes.
So a migration file will be written, which is applied to staging. Once that's considered stable there's a prod release which goes out, and replicas are updated at the same time.
Alembic has a table with a migration ID, so you can see what migration different databases are on
That's a rough overview, I've no idea how things work in SQL server land though.
1
u/mu_SQL Apr 23 '26
Wibe code a client, I did one for Elastic pool to manage scripts going to multipel databases(kinda like servers).
1
u/reditandfirgetit Apr 24 '26
In SSMS register the servers in a group. Provided the objects have the same schema, you can run a query against all servers in your group
1
u/downshiftdata Apr 25 '26
I've had a homebrew powershell script I've used for years, running the scripts out of a repo (where they belong). I got dragged into using Flyway, only to find that the repeatable scripts feature closely matches what I was doing. Quite happy with it.
1
u/Fresh_Pollution4260 Apr 25 '26
You can create an SSIS package that uses expressions to iterate over each of your connection strings from a table in a main database. The package will run the script through a loop of your db connection strings