Last week I posted a quick example of looping through multiple servers using SSIS and being in a bit of a hurry I didn’t really finish. Last time I created the loop and got it working, but didn’t do anything with it. So this time I’m going to demonstrate using the loop to pull a list of databases and some information about each from the three different servers I set up last time into a central location.
SELECT TOP 0 @@SERVERNAME AS Server_Name, sys.databases.database_id, sys.databases.name, sys.server_principals.name AS database_owner, sys.databases.compatibility_level, sys.databases.collation_name, sys.databases.recovery_model_desc, sys.databases.page_verify_option_desc INTO Database_List FROM sys.databases JOIN sys.server_principals ON sys.databases.owner_sid = sys.server_principals.sid
CREATE UNIQUE CLUSTERED INDEX pk_Database_List ON Database_List(Server_Name, database_id)



SELECT @@SERVERNAME AS Server_Name, sys.databases.database_id, sys.databases.name, sys.server_principals.name AS database_owner, sys.databases.compatibility_level, sys.databases.collation_name, sys.databases.recovery_model_desc, sys.databases.page_verify_option_desc INTO Database_List FROM sys.databases JOIN sys.server_principals ON sys.databases.owner_sid = sys.server_principals.sid
At this point you should be able to run the package and pull your database list for the servers set up in the loop. Next week I’ll demonstrate pulling the list of servers from a table.