Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Batch file script to run query against multiple servers

$
0
0

Hi All,

I'm using the below batch file script to run a query(select name,state_desc from sys.databases) which i saved in sqlquery1.sql and the output gets exported to an excel file when i run the below batch script which is saved as myfirstbatch.bat, but I'm doing this for a single instance of SQL server. How can i modify the below script in such a way that the script executes, same query on multiple SQL instances. There are around 5000 servers against which i have to execute the same query.

echo off
sqlcmd -E -S karthik-pc\sql2k8instance1 -i O:\batch\sqlquery1.sql -o o:\batch\output.csv -s ","
set /p delExit=press the Enter key to exit...:

Thanks in Advance.

Regards, Kranthi



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>