Skip to content
Advertisement

Executing SQL query on multiple databases

I know my post has a very similar title to other ones in this forum, but I really couldn’t find the answer I need.

Here is my problem, I have a SQL Server running on my Windows Server. Inside my SQL Server, I have around 30 databases. All of them have the same tables, and the same stored procedures.

Now, here is the problem, I have this huge script that I need to run in all of these databases. I wish I could do it just once against all my databases.

I tried a couple things like go to “view” >> registered servers >> local server groups >> new server registration. But this solution is for many servers, not many databases.

I know I could do it by typing the database name, but the query is really huge, so it would take too long to run in all databases.

Does anybody have any idea if that is possible?

Advertisement

Answer

ApexSQL Propagate is the tool which can help in this situation. It is used for executing single or multiple scripts on multiple databases, even multiple servers. What you should do is simply select that script, then select all databases against which you want to execute that script:

select databases

When you load scripts and databases you should just click the “Execute” button and wait for the results:

click the execute button

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement