I have a MS SQL Server 2005 server. I have a login that has db_datareader and db_datadenywriter to one of the DBs on that server. I need to add these same mappings to about 40 more DBs, and I don't want to do it manually... especially since this is for our lab and I'll have to do the same in our production environment later.
All of the DBs are named following a pattern, and they all end with the same last three letters.
To do one DB at a time, i tried this:
SQL
USEMyDatabaseNameHereGOEXECsp_addrolemember'db_datareader','MYDOMAIN\MyServiceAccount'EXECsp_addrolemember'db_denydatawriter','MYDOMAIN\MyServiceAccount'
This partially works. If I look at the mappings for MyServiceAccount, the check box is not there for MyDatabase. But if I check the box, then I can see that the roles I tried to assign are checked. Okay, not what I want,...