|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, April 08, 2013 6:31 AM
Points: 5,
Visits: 48
|
|
Hi
I'm currently looking for a script to get a list of all databases from our SQL 2005 and above instances. Currently I have to pull this weekly from each instance alone but I don't know how to get this more automated.
Can anyone help me?
Thanks in advance and Kind Regards angelspawn
I currently use the script from here
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 9:14 AM
Points: 4,428,
Visits: 7,196
|
|
SELECT name FROM sys.databases will solve the problem you describe, although I can't help suspecting that your requirement is somewhat more complex than that. You can use a Central Management Server to run it on all servers at once, or use SSIS to loop through your servers one at a time, or you can set up each server as a linked server and run the query like that.
John
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 6:47 AM
Points: 46,
Visits: 176
|
|
if you having sql server mgmt studio 2008,
you can registered no of instance using central server mgmt .
once registration done u can directly execute query on multiple instance.
PFA.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, April 08, 2013 6:31 AM
Points: 5,
Visits: 48
|
|
We have everything from SQL 2005 up to SQL 2008R2 SSMS.
I currently have a SQL 2005 server where i have all others added as linked server.
Thanks again for your ideas I will try them out
angelspawn
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 12:13 PM
Points: 130,
Visits: 512
|
|
@angelspawn Part of the challenge to be a successful DBA is to use the tools at our disposal to answer these types of questions. There are [several] ways to answer your own question using batch files, PowerShell, SSMS, scripts, etc.
My batch file suggestion is only one possible way to accomplish this. I'll assume you have administrator access to all SQL Servers in your domain. Check dblist.txt on completion.
@ECHO OFF SQLCMD -Lc > serverlist.txt FOR /F %%i IN (serverlist.txt) DO ( SQLCMD /S %%i /E /d master -o dblist.txt /Q"SET NOCOUNT ON SELECT SUBSTRING(@@SERVERNAME, 1, 30) AS ServerName, SUBSTRING([name],1,40) AS DBName FROM sysdatabases ORDER BY NAME SET NOCOUNT OFF;" )
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 12:13 PM
Points: 130,
Visits: 512
|
|
<LOL> And my way is wrong! I [just] realized dblist.txt will be [overwritten] for each server. My bad. Here's a corrected batch file:
@ECHO OFF SQLCMD -Lc > serverlist.txt FOR /F %%i IN (serverlist.txt) DO ( SQLCMD /S %%i /E /d master /Q"SET NOCOUNT ON SELECT SUBSTRING(@@SERVERNAME, 1, 30) AS ServerName, SUBSTRING([name],1,40) AS DBName FROM sysdatabases ORDER BY NAME SET NOCOUNT OFF;" >>dblist.txt )
|
|
|
|