Asked By schal
09-Aug-07 01:38 PM

There are multiple ways of doing this.
Create a .CMD file with this statement:
------------------------------------------------------------------------------------------------------------------------------------------------
sqlcmd -s <servername1> -Q "EXEC sp_MSForEachDB @Command1 = N'DBCC
SHRINKDATABASE (?, 10)', @replacechar = '?'" -c go
sqlcmd -s <servername2> -Q "EXEC sp_MSForEachDB @Command1 = N'DBCC
SHRINKDATABASE (?, 10)', @replacechar = '?'" -c go
sqlcmd -s <servername3> -Q "EXEC sp_MSForEachDB @Command1 = N'DBCC
SHRINKDATABASE (?, 10)', @replacechar = '?'" -c go
sqlcmd -s <servername4> -Q "EXEC sp_MSForEachDB @Command1 = N'DBCC
SHRINKDATABASE (?, 10)', @replacechar = '?'" -c go
sqlcmd -s <servername5> -Q "EXEC sp_MSForEachDB @Command1 = N'DBCC
SHRINKDATABASE (?, 10)', @replacechar = '?'" -c go
------------------------------------------------------------------------------------------------------------------------------------------------
Replace the <servername> with your servername
For each server add a new line and with the changed servername
(to create a CMD file: open notepad and paste the final script and
save it as scriptfile.cmd)
Once you have the CMD file, open commandprompt and go to the drive
location and enter the name of the file
In my case it is:
------------------------------------------------------------------------------------------------------------------------------------------------
c:\dbccscript.cmd
------------------------------------------------------------------------------------------------------------------------------------------------
This will display all the output to the commandprompt. You can
redirect all the output to a log/txt file using -o switch in the cmd
script.
Note that sqlcmd is a new utility in MS SQL server 2005.
in SQL Server 2000 you can achieve the same using "OSQL" books online
has enuf info on this to help you rewrite it for osql.
Regards,
schal