SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Script or Tip to add login
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Analyzer
Posting Yak Master

United Kingdom
101 Posts

Posted - 09/16/2013 :  12:27:36  Show Profile  Reply with Quote
Hi,

Need to write a script that maps a proxy account (already created) to every database with database role db_backupoperator.

Next problem is there are 200 sql instances (2000, 2005, 2008, 2012) so the syntax will be changing.

The proxy account will always be the same but the instance name\databases will change of course. So would need to make the script generic to run within SQL Group Multi Query.

Any ideas the most efficient method to complete this?

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1754 Posts

Posted - 09/16/2013 :  19:05:11  Show Profile  Reply with Quote
Within a server can be solved with the undocumented sproc sp_MSforeachdatabase. Here's a link to its usage: http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm

Syntax can be resolved by first querying the @@Version and using the syntax appropriate to the version.


=================================================
The cure for anything is salt water -- sweat, tears, or the sea. -Isak Dinesen
Go to Top of Page

Analyzer
Posting Yak Master

United Kingdom
101 Posts

Posted - 09/18/2013 :  06:53:28  Show Profile  Reply with Quote
Hi - thanks for the direction.

Next issue I have is supplying a variable in the command since this script will be run against 100s servers.

Any ideas how I get sp_MSforeachdb to accept my variable. I have tried the below but it fails. Any ideas?


DECLARE @sqlCommand VARCHAR(2000)
declare @svr as varchar(30)
set @svr = 'select @@servername'

SET @sqlCommand =
'USE ; CREATE USER [@svr\shellLocalUser] FOR LOGIN [@svr\shellLocalUser];'

EXEC master..sp_MSForeachdb @sqlCommand
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000