Question

I am trying to create a SQL Job that sits on what I like to call a Maintenance Server where details about all the other server databases sit. So I have a stored procedure to gather all the required data I have and this stored procedure is now in MaintenanceServer.MaintenanceDB.pr_MyProcedure.

Now what i'd like to do this is. I am creating Linked Servers on my MaintenanceServer which points to all the other Servers I'd like to maintain. Next on my list is to be able to run this procedure pr_MyProcedure against all those LinkedServers. I have over 25 servers to maintain and what i want to do is to run the procedure against them and insert the result to my local MaintenanceDB.

Can someone point me to a good way to do this? Also i'd like to hear the drawbacks of this method.

Thanks and Cheers!

EDIT:

I was also thinking about storing the SP on all the master databases of my other Servers and running them remotely on my Maintenance Server. Then i'll use OPENQUERY() to gather all the results that I need. However, I don't think I want to touch all the master databases on my server list. Please tell me if this would be better than the once I stated above.

Was it helpful?

Solution

The nice way to do it is run the SP on the target server, as that's nicely modular. If you want to query the remote server, it's going to be more painful. I'm not sure whether the undocumented sp_foreachdb deals with linked databases, if not you are down to dynamic sql.

As in build a string and call it with Exec(@somesql), that will need to deal with the results itself, as any variables will only be in scope inside the exec.

Personally I'd consider inverting all this. Have each server call it's own SP and the call an SP on the maintenance box to store the results.

OTHER TIPS

EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName

‘Params’ Example:

EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName ’PramValue’

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top