Need to use the database name while creating the role

5 pts.
Tags:
Database name
Scripting
Server Database
I need to create 2 database roles(need to write the script for this task) databasename_dbo_reader and databasename_dbo_writer for all the databases on a server. I have tried the below Declare @databasename sysname SELECT @databasename = (SELECT DB_NAME()) exec ('CREATE ROLE'+ @databasename+'_DBO_WRITER') but throughing some syntax error.Please help.

Answer Wiki

Thanks. We'll let you know when a new response is added.

This should do the trick, but I haven’t tested it.

<pre>exec sp_MSforeachdb ‘CREATE ROLE?_DBO_WRITER’</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • PrasannaSql
    [...] Did you test out Mrdenny’s suggestion for using the database name while creating the role. 6. Mrdenny and Mattburnett discuss the pros and cons of replacing a Windows network with iPad 2s [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following