I have a role / login in a 'new' database mynewdb with a role "emailsender". I have scripted a profile for sp_send_dbmail and am now trying to script adding the the login to the DatabaseMailUserRole in msdb and seem to be going around in circles. Importantly I want to run my update script in mynewdb. I know I can use SSMS to do this. The question is:

How to script adding the user to the role in T-SQL from the mynewdb database without switching to msdb?

EXEC msdb.sys.sp_executesql N'ALTER ROLE ...';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.